summary refs log tree commit diff
path: root/pkgs
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2017-10-25 15:35:45 +0200
committerEelco Dolstra <edolstra@gmail.com>2017-10-25 15:38:14 +0200
commit8f349a3bf3cc9a2a4733a25d66cd06309bb4d586 (patch)
tree7d2772af5f333ecc0c5f826f0ea3700394ac8737 /pkgs
parent5939af52b32c01edca7ad4c363b627970db3e04e (diff)
downloadnixlib-8f349a3bf3cc9a2a4733a25d66cd06309bb4d586.tar
nixlib-8f349a3bf3cc9a2a4733a25d66cd06309bb4d586.tar.gz
nixlib-8f349a3bf3cc9a2a4733a25d66cd06309bb4d586.tar.bz2
nixlib-8f349a3bf3cc9a2a4733a25d66cd06309bb4d586.tar.lz
nixlib-8f349a3bf3cc9a2a4733a25d66cd06309bb4d586.tar.xz
nixlib-8f349a3bf3cc9a2a4733a25d66cd06309bb4d586.tar.zst
nixlib-8f349a3bf3cc9a2a4733a25d66cd06309bb4d586.zip
Add function closureInfo to replace pathsFromGraph
Unlike pathsFromGraph, on Nix 1.12, this function produces a
registration file containing correct NAR hash/size information.

https://hydra.nixos.org/build/62832723
Diffstat (limited to 'pkgs')
-rw-r--r--pkgs/build-support/closure-info.nix55
-rw-r--r--pkgs/top-level/all-packages.nix2
2 files changed, 57 insertions, 0 deletions
diff --git a/pkgs/build-support/closure-info.nix b/pkgs/build-support/closure-info.nix
new file mode 100644
index 000000000000..f1b0930cdcff
--- /dev/null
+++ b/pkgs/build-support/closure-info.nix
@@ -0,0 +1,55 @@
+# This derivation builds two files containing information about the
+# closure of 'rootPaths': $out/store-paths contains the paths in the
+# closure, and $out/registration contains a file suitable for use with
+# "nix-store --load-db" and "nix-store --register-validity
+# --hash-given".
+
+{ stdenv, coreutils, jq, perl, pathsFromGraph }:
+
+{ rootPaths }:
+
+if builtins.langVersion >= 5 then
+
+  # Nix >= 1.12: Include NAR hash / size info.
+
+  stdenv.mkDerivation {
+    name = "closure-info";
+
+    __structuredAttrs = true;
+
+    exportReferencesGraph.closure = rootPaths;
+
+    PATH = "${coreutils}/bin:${jq}/bin";
+
+    builder = builtins.toFile "builder"
+      ''
+        if [ -e .attrs.sh ]; then . .attrs.sh; fi
+
+        out=''${outputs[out]}
+
+        mkdir $out
+
+        jq -r '.closure | map([.path, .narHash, .narSize, "", (.references | length)] + .references) | add | map("\(.)\n") | add' < .attrs.json | head -n -1 > $out/registration
+        jq -r .closure[].path < .attrs.json > $out/store-paths
+      '';
+  }
+
+else
+
+  # Nix < 1.12
+
+  stdenv.mkDerivation {
+    name = "closure-info";
+
+    exportReferencesGraph =
+      map (x: [("closure-" + baseNameOf x) x]) rootPaths;
+
+    buildInputs = [ perl ];
+
+    buildCommand =
+      ''
+        mkdir $out
+        printRegistration=1 perl ${pathsFromGraph} closure-* > $out/registration
+        perl ${pathsFromGraph} closure-* > $out/store-paths
+      '';
+  }
diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix
index 57d4ee6c3f55..ccc11caee717 100644
--- a/pkgs/top-level/all-packages.nix
+++ b/pkgs/top-level/all-packages.nix
@@ -305,6 +305,8 @@ with pkgs;
 
   pathsFromGraph = ../build-support/kernel/paths-from-graph.pl;
 
+  closureInfo = callPackage ../build-support/closure-info.nix { };
+
   setupSystemdUnits = callPackage ../build-support/setup-systemd-units.nix { };
 
   singularity-tools = callPackage ../build-support/singularity-tools { };