1 # This derivation builds two files containing information about the
2 # closure of 'rootPaths': $out/store-paths contains the paths in the
3 # closure, and $out/registration contains a file suitable for use with
4 # "nix-store --load-db" and "nix-store --register-validity
7 { stdenvNoCC, coreutils, jq }:
11 assert builtins.langVersion >= 5;
13 stdenvNoCC.mkDerivation {
14 name = "closure-info";
16 __structuredAttrs = true;
18 exportReferencesGraph.closure = rootPaths;
20 preferLocalBuild = true;
22 nativeBuildInputs = [ coreutils jq ];
24 empty = rootPaths == [];
32 if [[ -n "$empty" ]]; then
33 echo 0 > $out/total-nar-size
34 touch $out/registration $out/store-paths
36 jq -r ".closure | map(.narSize) | add" < "$NIX_ATTRS_JSON_FILE" > $out/total-nar-size
37 jq -r '.closure | map([.path, .narHash, .narSize, "", (.references | length)] + .references) | add | map("\(.)\n") | add' < "$NIX_ATTRS_JSON_FILE" | head -n -1 > $out/registration
38 jq -r '.closure[].path' < "$NIX_ATTRS_JSON_FILE" > $out/store-paths