summary refs log tree commit diff
path: root/modules/installer/cd-dvd/system-tarball.nix
blob: e0cbfd6e71318a3dbdd0d10ded9ae6a43dea955b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# This module creates a bootable ISO image containing the given NixOS
# configuration.  The derivation for the ISO image will be placed in
# config.system.build.tarball.

{ config, pkgs, ... }:

with pkgs.lib;

let

  options = {
    tarball.contents = mkOption {
      example =
        [ { source = pkgs.memtest86 + "/memtest.bin";
            target = "boot/memtest.bin";
          }
        ];
      description = ''
        This option lists files to be copied to fixed locations in the
        generated ISO image.
      '';
    };

    tarball.storeContents = mkOption {
      example = [pkgs.stdenv];
      description = ''
        This option lists additional derivations to be included in the
        Nix store in the generated ISO image.
      '';
    };

  };

  versionFile = pkgs.writeText "nixos-version" config.system.nixosVersion;

in

{
  require = options;

  # In stage 1 of the boot, mount the CD/DVD as the root FS by label
  # so that we don't need to know its device.
  fileSystems = [ ];

  # boot.initrd.availableKernelModules = [ "mvsdio" "mmc_block" "reiserfs" "ext3" "ext4" ];

  # boot.initrd.kernelModules = [ "rtc_mv" ];

  # Closures to be copied to the Nix store on the CD, namely the init
  # script and the top-level system configuration directory.
  tarball.storeContents =
    [ { object = config.system.build.toplevel;
        symlink = "/run/current-system";
      }
    ];

  # Individual files to be included on the CD, outside of the Nix
  # store on the CD.
  tarball.contents =
    [ { source = config.system.build.initialRamdisk + "/initrd";
        target = "/boot/initrd";
      }
      { source = versionFile;
        target = "/nixos-version.txt";
      }
    ];

  # Create the tarball
  system.build.tarball = import ../../../lib/make-system-tarball.nix {
    inherit (pkgs) stdenv perl xz pathsFromGraph;

    inherit (config.tarball) contents storeContents;
  };

  # Otherwise it will collide with the 'ip=dhcp' kernel autoconfig.
  networking.useDHCP = false;

  boot.postBootCommands =
    ''
      # After booting, register the contents of the Nix store on the
      # CD in the Nix database in the tmpfs.
      if [ -f /nix-path-registration ]; then
        ${config.environment.nix}/bin/nix-store --load-db < /nix-path-registration &&
        rm /nix-path-registration
      fi

      # nixos-rebuild also requires a "system" profile and an
      # /etc/NIXOS tag.
      touch /etc/NIXOS
      ${config.environment.nix}/bin/nix-env -p /nix/var/nix/profiles/system --set /run/current-system
    '';
}