···33333434, name ? "nixos-disk-image"
35353636-, format ? "raw"
3636+, # Disk image format, one of qcow2, vpc, raw.
3737+ format ? "raw"
3738}:
38393940with lib;
···4546 raw = "img";
4647 };
47484848- nixpkgs = lib.cleanSource pkgs.path;
4949+ nixpkgs = cleanSource pkgs.path;
49505051 channelSources = pkgs.runCommand "nixos-${config.system.nixosVersion}" {} ''
5152 mkdir -p $out
···6465 ${channelSources}
6566 '';
66676767- prepareImageInputs = with pkgs; [ rsync utillinux parted e2fsprogs lkl fakeroot libfaketime config.system.build.nixos-prepare-root ] ++ stdenv.initialPath;
6868+ prepareImageInputs = with pkgs; [ rsync utillinux parted e2fsprogs lkl fakeroot config.system.build.nixos-prepare-root ] ++ stdenv.initialPath;
68696970 # I'm preserving the line below because I'm going to search for it across nixpkgs to consolidate
7071 # image building logic. The comment right below this now appears in 4 different places in nixpkgs :)
···7374 targets = map (x: x.target) contents;
74757576 prepareImage = ''
7676- export PATH=${pkgs.lib.makeSearchPathOutput "bin" "bin" prepareImageInputs}
7777+ export PATH=${makeSearchPathOutput "bin" "bin" prepareImageInputs}
77787879 mkdir $out
7980 diskImage=nixos.raw
···8687 offset=0
8788 ''}
88898989- faketime -f "1970-01-01 00:00:01" mkfs.${fsType} -F -L nixos -E offset=$offset $diskImage
9090-9090+ mkfs.${fsType} -F -L nixos -E offset=$offset $diskImage
9191+9192 root="$PWD/root"
9293 mkdir -p $root
9394···124125 fakeroot nixos-prepare-root $root ${channelSources} ${config.system.build.toplevel} closure
125126126127 echo "copying staging root to image..."
127127- # If we don't faketime, we can end up with timestamps other than 1 on the nix store, which
128128- # will confuse Nix in some situations (e.g., breaking image builds in the target image)
129129- # N.B: I use 0 here, which results in timestamp = 1 in the image. It's weird but see
130130- # https://github.com/lkl/linux/issues/393. Also, running under faketime makes `cptofs` super
131131- # noisy and it prints out that it can't find a bunch of files, and then works anyway. We'll
132132- # shut it up someday but trying to do a stderr filter through grep is running into some nasty
133133- # bug in some eval nonsense we have in runInLinuxVM and I'm sick of trying to fix it.
134134- faketime -f "1970-01-01 00:00:00" \
135135- cptofs ${pkgs.lib.optionalString partitioned "-P 1"} -t ${fsType} -i $diskImage $root/* /
128128+ cptofs ${pkgs.lib.optionalString partitioned "-P 1"} -t ${fsType} -i $diskImage $root/* /
136129 '';
137130in pkgs.vmTools.runInLinuxVM (
138131 pkgs.runCommand name