diff --git a/pkgs/build-support/docker/default.nix b/pkgs/build-support/docker/default.nix index 2d6d6c1fc91d8..59e0ce71c7222 100644 --- a/pkgs/build-support/docker/default.nix +++ b/pkgs/build-support/docker/default.nix @@ -23,6 +23,7 @@ referencesByPopularity, writeScript, writeText, + closureInfo, }: # WARNING: this API is unstable and may be subject to backwards-incompatible changes in the future. @@ -261,18 +262,11 @@ rec { ${text} ''; - nixRegistration = contents: runCommand "nix-registration" { - buildInputs = [ nix perl ]; - # For obtaining the closure of `contents'. - exportReferencesGraph = - let contentsList = if builtins.isList contents then contents else [ contents ]; - in map (x: [("closure-" + baseNameOf x) x]) contentsList; - } - '' - mkdir $out - printRegistration=1 perl ${pkgs.pathsFromGraph} closure-* > $out/db.dump - perl ${pkgs.pathsFromGraph} closure-* > $out/storePaths - ''; + nixRegistration = contents: + let + rootPaths = if builtins.isList contents then contents else [ contents ]; + in + closureInfo { inherit rootPaths; }; # Create $maxLayers worth of Docker Layers, one layer per store path # unless there are more paths than $maxLayers. In that case, create @@ -795,6 +789,9 @@ rec { # the container. # Be careful since this doesn't work well with multilayer. buildImageWithNixDb = args@{ contents ? null, extraCommands ? "", ... }: + let + registrationInfo = nixRegistration contents; + in buildImage (args // { extraCommands = '' echo "Generating the nix database..." @@ -803,7 +800,7 @@ rec { echo " be better to only have one layer that contains a nix store." # This requires Nix 1.12 or higher export NIX_REMOTE=local?root=$PWD - ${nix}/bin/nix-store --load-db < ${nixRegistration contents}/db.dump + ${nix}/bin/nix-store --load-db < ${registrationInfo}/registration # We fill the store in order to run the 'verify' command that # generates hash and size of output paths. @@ -811,7 +808,7 @@ rec { # generated by the exportReferencesGraph function will # contains sha and size. See # https://github.com/NixOS/nix/commit/c2b0d8749f7e77afc1c4b3e8dd36b7ee9720af4a - storePaths=$(cat ${nixRegistration contents}/storePaths) + storePaths=$(cat ${registrationInfo}/store-paths) echo "Copying everything to /nix/store (will take a while)..." cp -prd $storePaths nix/store/ ${nix}/bin/nix-store --verify --check-contents