2017-10-25 13:35:45 +00:00
|
|
|
# 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".
|
|
|
|
|
2024-09-26 07:33:42 +00:00
|
|
|
{ stdenvNoCC, coreutils, jq }:
|
2017-10-25 13:35:45 +00:00
|
|
|
|
|
|
|
{ rootPaths }:
|
|
|
|
|
2018-02-07 14:47:19 +00:00
|
|
|
assert builtins.langVersion >= 5;
|
2017-10-25 13:35:45 +00:00
|
|
|
|
2024-09-26 07:33:42 +00:00
|
|
|
stdenvNoCC.mkDerivation {
|
2018-02-07 14:47:19 +00:00
|
|
|
name = "closure-info";
|
2017-10-25 13:35:45 +00:00
|
|
|
|
2018-02-07 14:47:19 +00:00
|
|
|
__structuredAttrs = true;
|
2017-10-25 13:35:45 +00:00
|
|
|
|
2018-02-07 14:47:19 +00:00
|
|
|
exportReferencesGraph.closure = rootPaths;
|
2017-10-25 13:35:45 +00:00
|
|
|
|
2018-11-08 10:59:03 +00:00
|
|
|
preferLocalBuild = true;
|
|
|
|
|
2023-09-28 17:25:28 +00:00
|
|
|
nativeBuildInputs = [ coreutils jq ];
|
2017-10-25 13:35:45 +00:00
|
|
|
|
2023-11-04 08:54:41 +00:00
|
|
|
empty = rootPaths == [];
|
|
|
|
|
2023-09-28 17:25:28 +00:00
|
|
|
buildCommand =
|
2018-02-07 14:47:19 +00:00
|
|
|
''
|
|
|
|
out=''${outputs[out]}
|
2017-10-25 13:35:45 +00:00
|
|
|
|
2018-02-07 14:47:19 +00:00
|
|
|
mkdir $out
|
2017-10-25 13:35:45 +00:00
|
|
|
|
2023-11-04 08:54:41 +00:00
|
|
|
if [[ -n "$empty" ]]; then
|
|
|
|
echo 0 > $out/total-nar-size
|
|
|
|
touch $out/registration $out/store-paths
|
|
|
|
else
|
|
|
|
jq -r ".closure | map(.narSize) | add" < "$NIX_ATTRS_JSON_FILE" > $out/total-nar-size
|
|
|
|
jq -r '.closure | map([.path, .narHash, .narSize, "", (.references | length)] + .references) | add | map("\(.)\n") | add' < "$NIX_ATTRS_JSON_FILE" | head -n -1 > $out/registration
|
|
|
|
jq -r '.closure[].path' < "$NIX_ATTRS_JSON_FILE" > $out/store-paths
|
|
|
|
fi
|
|
|
|
|
2018-02-07 14:47:19 +00:00
|
|
|
'';
|
|
|
|
}
|