From 926327e644e91001af1619a37f393537ff235614 Mon Sep 17 00:00:00 2001 From: Ding Xiang Fei Date: Thu, 13 Sep 2018 00:21:27 +0800 Subject: [PATCH] use closureInfo --- pkgs/build-support/docker/default.nix | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/pkgs/build-support/docker/default.nix b/pkgs/build-support/docker/default.nix index bc79f9ff12fd1..6f4f46a15ee7f 100644 --- a/pkgs/build-support/docker/default.nix +++ b/pkgs/build-support/docker/default.nix @@ -21,6 +21,7 @@ writeReferencesToFile, writeScript, writeText, + closureInfo, }: # WARNING: this API is unstable and may be subject to backwards-incompatible changes in the future. @@ -257,18 +258,11 @@ rec { ${text} ''; - nixRegistration = contents: runCommand "nix-registration" { - buildInputs = [ nixUnstable 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 a "layer" (set of files). mkPureLayer = { @@ -611,6 +605,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..." @@ -619,7 +616,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 - ${nixUnstable}/bin/nix-store --load-db < ${nixRegistration contents}/db.dump + ${nixUnstable}/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. @@ -627,7 +624,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/ ${nixUnstable}/bin/nix-store --verify --check-contents