closureInfo: handle empty path set explicitly

Arguably, this is a bug in Nix's structuredAttrs: without
structuredAttrs, exportReferencesGraph with an empty path set would
still result in information being provided. With structuredAttrs, no
info is provided for an empty path set.

Nevertheless, we need to be able to build even if Nix has the bug, so
work around it by checking for an empty path set and handling it
explicitly.
This commit is contained in:
Linus Heckemann 2023-11-04 09:54:41 +01:00
parent 10d3ba75f0
commit bdd23d10b2

View File

@ -21,14 +21,22 @@ stdenv.mkDerivation {
nativeBuildInputs = [ coreutils jq ]; nativeBuildInputs = [ coreutils jq ];
empty = rootPaths == [];
buildCommand = buildCommand =
'' ''
out=''${outputs[out]} out=''${outputs[out]}
mkdir $out mkdir $out
jq -r ".closure | map(.narSize) | add" < "$NIX_ATTRS_JSON_FILE" > $out/total-nar-size if [[ -n "$empty" ]]; then
jq -r '.closure | map([.path, .narHash, .narSize, "", (.references | length)] + .references) | add | map("\(.)\n") | add' < "$NIX_ATTRS_JSON_FILE" | head -n -1 > $out/registration echo 0 > $out/total-nar-size
jq -r '.closure[].path' < "$NIX_ATTRS_JSON_FILE" > $out/store-paths 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
''; '';
} }