git.iko.soy/typeable/nixpkgs
on master help sign in
dockerTools.buildImageWithNixDb: Make output paths valid and add gcroots

The database dump doesn't contain sha and size. This leads to invalid path in the container. We have to fix the database by using nix-store. Note a better way to do this is available in Nix 1.12 (since the database dump contains all required information). We also add content output paths in the gcroots since they ca be used by the container.

commitcb6fc52f998f8f3106a1506c052cffae752e8b7c authorAntoine Eiche <lewo@abesis.fr> dateWed 13 Sep 2017, 11:40 (9 years ago) parentdf589a4
1 file changed+20−2
pkgs/build-support/docker/default.nix+20−2
pkgs/build-support/docker/default.nix+20−2
@@ -249,7 +249,9 @@ rec {
249249 in map (x: [("closure-" + baseNameOf x) x]) contentsList;
250250 }
251251 ''
252− printRegistration=1 perl ${pkgs.pathsFromGraph} closure-* > $out
252+ mkdir $out
253+ printRegistration=1 perl ${pkgs.pathsFromGraph} closure-* > $out/db.dump
254+ perl ${pkgs.pathsFromGraph} closure-* > $out/storePaths
253255 '';
254256
255257 # Create a "layer" (set of files).
@@ -571,7 +573,23 @@ rec {
571573 echo " be better to only have one layer that contains a nix store."
572574 # This requires Nix 1.12 or higher
573575 export NIX_REMOTE=local?root=$PWD
574− ${nixUnstable}/bin/nix-store --load-db < ${nixRegistration contents}
576+ ${nixUnstable}/bin/nix-store --load-db < ${nixRegistration contents}/db.dump
577+
578+ # We fill the store in order to run the 'verify' command that
579+ # generates hash and size of output paths.
580+ # Note when Nix 1.12 is be the stable one, the database dump
581+ # generated by the exportReferencesGraph function will
582+ # contains sha and size. See
583+ # https://github.com/NixOS/nix/commit/c2b0d8749f7e77afc1c4b3e8dd36b7ee9720af4a
584+ storePaths=$(cat ${nixRegistration contents}/storePaths)
585+ echo "Copying everything to /nix/store (will take a while)..."
586+ cp -prd $storePaths nix/store/
587+ ${nixUnstable}/bin/nix-store --verify --check-contents
588+
589+ mkdir -p nix/var/nix/gcroots/docker/
590+ for i in ${lib.concatStringsSep " " contents}; do
591+ ln -s $i nix/var/nix/gcroots/docker/$(basename $i)
592+ done;
575593 '' + extraCommands;
576594 });
577595}