···3334, name ? "nixos-disk-image"
3536-, format ? "raw"
037}:
3839with lib;
···45 raw = "img";
46 };
4748- nixpkgs = lib.cleanSource pkgs.path;
4950 channelSources = pkgs.runCommand "nixos-${config.system.nixosVersion}" {} ''
51 mkdir -p $out
···64 ${channelSources}
65 '';
6667- prepareImageInputs = with pkgs; [ rsync utillinux parted e2fsprogs lkl fakeroot libfaketime config.system.build.nixos-prepare-root ] ++ stdenv.initialPath;
6869 # I'm preserving the line below because I'm going to search for it across nixpkgs to consolidate
70 # image building logic. The comment right below this now appears in 4 different places in nixpkgs :)
···73 targets = map (x: x.target) contents;
7475 prepareImage = ''
76- export PATH=${pkgs.lib.makeSearchPathOutput "bin" "bin" prepareImageInputs}
7778 mkdir $out
79 diskImage=nixos.raw
···86 offset=0
87 ''}
8889- faketime -f "1970-01-01 00:00:01" mkfs.${fsType} -F -L nixos -E offset=$offset $diskImage
90-91 root="$PWD/root"
92 mkdir -p $root
93···124 fakeroot nixos-prepare-root $root ${channelSources} ${config.system.build.toplevel} closure
125126 echo "copying staging root to image..."
127- # If we don't faketime, we can end up with timestamps other than 1 on the nix store, which
128- # will confuse Nix in some situations (e.g., breaking image builds in the target image)
129- # N.B: I use 0 here, which results in timestamp = 1 in the image. It's weird but see
130- # https://github.com/lkl/linux/issues/393. Also, running under faketime makes `cptofs` super
131- # noisy and it prints out that it can't find a bunch of files, and then works anyway. We'll
132- # shut it up someday but trying to do a stderr filter through grep is running into some nasty
133- # bug in some eval nonsense we have in runInLinuxVM and I'm sick of trying to fix it.
134- faketime -f "1970-01-01 00:00:00" \
135- cptofs ${pkgs.lib.optionalString partitioned "-P 1"} -t ${fsType} -i $diskImage $root/* /
136 '';
137in pkgs.vmTools.runInLinuxVM (
138 pkgs.runCommand name
···3334, name ? "nixos-disk-image"
3536+, # Disk image format, one of qcow2, vpc, raw.
37+ format ? "raw"
38}:
3940with lib;
···46 raw = "img";
47 };
4849+ nixpkgs = cleanSource pkgs.path;
5051 channelSources = pkgs.runCommand "nixos-${config.system.nixosVersion}" {} ''
52 mkdir -p $out
···65 ${channelSources}
66 '';
6768+ prepareImageInputs = with pkgs; [ rsync utillinux parted e2fsprogs lkl fakeroot config.system.build.nixos-prepare-root ] ++ stdenv.initialPath;
6970 # I'm preserving the line below because I'm going to search for it across nixpkgs to consolidate
71 # image building logic. The comment right below this now appears in 4 different places in nixpkgs :)
···74 targets = map (x: x.target) contents;
7576 prepareImage = ''
77+ export PATH=${makeSearchPathOutput "bin" "bin" prepareImageInputs}
7879 mkdir $out
80 diskImage=nixos.raw
···87 offset=0
88 ''}
8990+ mkfs.${fsType} -F -L nixos -E offset=$offset $diskImage
91+92 root="$PWD/root"
93 mkdir -p $root
94···125 fakeroot nixos-prepare-root $root ${channelSources} ${config.system.build.toplevel} closure
126127 echo "copying staging root to image..."
128+ cptofs ${pkgs.lib.optionalString partitioned "-P 1"} -t ${fsType} -i $diskImage $root/* /
00000000129 '';
130in pkgs.vmTools.runInLinuxVM (
131 pkgs.runCommand name