@@ -64,7 +64,7 @@ let
6464 ${channelSources}
6565 '';
6666
67− prepareImageInputs = with pkgs; [ rsync utillinux parted e2fsprogs lkl fakeroot config.system.build.nixos-prepare-root ] ++ stdenv.initialPath;
67+ prepareImageInputs = with pkgs; [ rsync utillinux parted e2fsprogs lkl fakeroot libfaketime config.system.build.nixos-prepare-root ] ++ stdenv.initialPath;
6868
6969 # I'm preserving the line below because I'm going to search for it across nixpkgs to consolidate
7070 # image building logic. The comment right below this now appears in 4 different places in nixpkgs :)
@@ -86,7 +86,7 @@ let
8686 offset=0
8787 ''}
8888
89− mkfs.${fsType} -F -L nixos -E offset=$offset $diskImage
89+ faketime -f "1970-01-01 00:00:01" mkfs.${fsType} -F -L nixos -E offset=$offset $diskImage
9090
9191 root="$PWD/root"
9292 mkdir -p $root
@@ -124,7 +124,15 @@ let
124124 fakeroot nixos-prepare-root $root ${channelSources} ${config.system.build.toplevel} closure
125125
126126 echo "copying staging root to image..."
127− cptofs ${pkgs.lib.optionalString partitioned "-P 1"} -t ${fsType} -i $diskImage $root/* /
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/* /
128136 '';
129137in pkgs.vmTools.runInLinuxVM (
130138 pkgs.runCommand name