2024-05-02 00:46:19 +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-06-30 08:12:46 +00:00
|
|
|
{
|
|
|
|
stdenv,
|
|
|
|
coreutils,
|
|
|
|
jq,
|
|
|
|
}:
|
2024-05-02 00:46:19 +00:00
|
|
|
|
|
|
|
{ rootPaths }:
|
|
|
|
|
|
|
|
assert builtins.langVersion >= 5;
|
|
|
|
|
|
|
|
stdenv.mkDerivation {
|
|
|
|
name = "closure-info";
|
|
|
|
|
|
|
|
__structuredAttrs = true;
|
|
|
|
|
|
|
|
exportReferencesGraph.closure = rootPaths;
|
|
|
|
|
|
|
|
preferLocalBuild = true;
|
|
|
|
|
2024-06-30 08:12:46 +00:00
|
|
|
nativeBuildInputs = [
|
|
|
|
coreutils
|
|
|
|
jq
|
|
|
|
];
|
2024-05-02 00:46:19 +00:00
|
|
|
|
2024-06-30 08:12:46 +00:00
|
|
|
empty = rootPaths == [ ];
|
2024-05-02 00:46:19 +00:00
|
|
|
|
2024-06-30 08:12:46 +00:00
|
|
|
buildCommand = ''
|
|
|
|
out=''${outputs[out]}
|
2024-05-02 00:46:19 +00:00
|
|
|
|
2024-06-30 08:12:46 +00:00
|
|
|
mkdir $out
|
2024-05-02 00:46:19 +00:00
|
|
|
|
2024-06-30 08:12:46 +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
|
2024-05-02 00:46:19 +00:00
|
|
|
|
2024-06-30 08:12:46 +00:00
|
|
|
'';
|
2024-05-02 00:46:19 +00:00
|
|
|
}
|