2017-10-25 14:35:45 +01: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".
|
|
|
|
|
2023-09-28 18:25:28 +01:00
|
|
|
{ stdenv, coreutils, jq }:
|
2017-10-25 14:35:45 +01:00
|
|
|
|
|
|
|
{ rootPaths }:
|
|
|
|
|
2018-02-07 14:47:19 +00:00
|
|
|
assert builtins.langVersion >= 5;
|
2017-10-25 14:35:45 +01:00
|
|
|
|
2018-02-07 14:47:19 +00:00
|
|
|
stdenv.mkDerivation {
|
|
|
|
name = "closure-info";
|
2017-10-25 14:35:45 +01:00
|
|
|
|
2018-02-07 14:47:19 +00:00
|
|
|
__structuredAttrs = true;
|
2017-10-25 14:35:45 +01:00
|
|
|
|
2018-02-07 14:47:19 +00:00
|
|
|
exportReferencesGraph.closure = rootPaths;
|
2017-10-25 14:35:45 +01:00
|
|
|
|
2018-11-08 10:59:03 +00:00
|
|
|
preferLocalBuild = true;
|
|
|
|
|
2023-09-28 18:25:28 +01:00
|
|
|
nativeBuildInputs = [ coreutils jq ];
|
2017-10-25 14:35:45 +01:00
|
|
|
|
2023-11-04 08:54:41 +00:00
|
|
|
empty = rootPaths == [];
|
|
|
|
|
2023-09-28 18:25:28 +01:00
|
|
|
buildCommand =
|
2018-02-07 14:47:19 +00:00
|
|
|
''
|
|
|
|
out=''${outputs[out]}
|
2017-10-25 14:35:45 +01:00
|
|
|
|
2018-02-07 14:47:19 +00:00
|
|
|
mkdir $out
|
2017-10-25 14:35:45 +01: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
|
|
|
'';
|
|
|
|
}
|