summary refs log tree commit diff
path: root/nixos/lib/make-disk-image.nix
diff options
context:
space:
mode:
Diffstat (limited to 'nixos/lib/make-disk-image.nix')
-rw-r--r--nixos/lib/make-disk-image.nix14
1 files changed, 11 insertions, 3 deletions
diff --git a/nixos/lib/make-disk-image.nix b/nixos/lib/make-disk-image.nix
index 9fa848301f60..865be297c066 100644
--- a/nixos/lib/make-disk-image.nix
+++ b/nixos/lib/make-disk-image.nix
@@ -64,7 +64,7 @@ let
     ${channelSources}
   '';
 
-  prepareImageInputs = with pkgs; [ rsync utillinux parted e2fsprogs lkl fakeroot config.system.build.nixos-prepare-root ] ++ stdenv.initialPath;
+  prepareImageInputs = with pkgs; [ rsync utillinux parted e2fsprogs lkl fakeroot libfaketime config.system.build.nixos-prepare-root ] ++ stdenv.initialPath;
 
   # I'm preserving the line below because I'm going to search for it across nixpkgs to consolidate
   # image building logic. The comment right below this now appears in 4 different places in nixpkgs :)
@@ -86,7 +86,7 @@ let
       offset=0
     ''}
 
-    mkfs.${fsType} -F -L nixos -E offset=$offset $diskImage
+    faketime -f "1970-01-01 00:00:01" mkfs.${fsType} -F -L nixos -E offset=$offset $diskImage
   
     root="$PWD/root"
     mkdir -p $root
@@ -124,7 +124,15 @@ let
     fakeroot nixos-prepare-root $root ${channelSources} ${config.system.build.toplevel} closure
 
     echo "copying staging root to image..."
-    cptofs ${pkgs.lib.optionalString partitioned "-P 1"} -t ${fsType} -i $diskImage $root/* /
+    # If we don't faketime, we can end up with timestamps other than 1 on the nix store, which
+    # will confuse Nix in some situations (e.g., breaking image builds in the target image)
+    # N.B: I use 0 here, which results in timestamp = 1 in the image. It's weird but see
+    # https://github.com/lkl/linux/issues/393. Also, running under faketime makes `cptofs` super
+    # noisy and it prints out that it can't find a bunch of files, and then works anyway. We'll
+    # shut it up someday but trying to do a stderr filter through grep is running into some nasty
+    # bug in some eval nonsense we have in runInLinuxVM and I'm sick of trying to fix it.
+    faketime -f "1970-01-01 00:00:00" \
+      cptofs ${pkgs.lib.optionalString partitioned "-P 1"} -t ${fsType} -i $diskImage $root/* /
   '';
 in pkgs.vmTools.runInLinuxVM (
   pkgs.runCommand name