Files
nixpkgs/pkgs/build-support/closure-info.nix
Dark Steveneq 646b892680
Some checks failed
Periodic Merges (6h) / master → staging-nixos (push) Failing after 12m50s
Periodic Merges (6h) / master → staging-next (push) Failing after 12m54s
Periodic Merges (24h) / merge-base(master,staging) → haskell-updates (push) Failing after 11m54s
Periodic Merges (6h) / staging-next → staging (push) Failing after 12m13s
Periodic Merges (24h) / staging-next-25.05 → staging-25.05 (push) Failing after 13m24s
Periodic Merges (24h) / release-25.05 → staging-next-25.05 (push) Failing after 14m28s
push sheeet
2025-10-09 14:15:47 +02:00

76 lines
1.6 KiB
Nix

{
stdenvNoCC,
coreutils,
jq,
}:
/**
Produces metadata about the closure of the given root paths.
1. Total NAR size in `$out/total-nar-size`.
2. Registration, suitable for `nix-store --load-db`, in `$out/registration`.
Can also be used with `nix-store --register-validity --hash-given`.
3. All store paths for the closure in `$out/store-paths`.
# Inputs
`rootPaths` ([Path])
: List of root paths to include in the closure information.
# Type
```
closureInfo :: { rootPaths :: [Path]; } -> Derivation
```
# Examples
:::{.example}
## `pkgs.closureInfo` usage example
```
pkgs.closureInfo {
rootPaths = [ pkgs.hello pkgs.bc pkgs.dwarf2json ];
}
=>
«derivation /nix/store/...-closure-info.drv»
```
:::
*/
{ rootPaths }:
assert builtins.langVersion >= 5;
stdenvNoCC.mkDerivation {
name = "closure-info";
__structuredAttrs = true;
exportReferencesGraph.closure = rootPaths;
preferLocalBuild = true;
nativeBuildInputs = [
coreutils
jq
];
empty = rootPaths == [ ];
buildCommand = ''
out=''${outputs[out]}
mkdir $out
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
'';
}