1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-12-22 17:01:08 +01:00

Add warning for non-JSON-object exportReferencesGraph

This will help users debug their mistakes.
This commit is contained in:
John Ericson 2025-12-09 13:02:46 -05:00
parent b398c14045
commit 1c63cf4001
2 changed files with 18 additions and 1 deletions

View file

@ -341,8 +341,12 @@ DerivationOptions<SingleDerivedPath> derivationOptionsFromStructuredAttrs(
if (parsed) { if (parsed) {
auto * e = optionalValueAt(parsed->structuredAttrs, "exportReferencesGraph"); auto * e = optionalValueAt(parsed->structuredAttrs, "exportReferencesGraph");
if (!e || !e->is_object()) if (!e)
return ret; return ret;
if (!e->is_object()) {
warn("'exportReferencesGraph' in structured attrs is not a JSON object, ignoring");
return ret;
}
for (auto & [key, storePathsJson] : getObject(*e)) { for (auto & [key, storePathsJson] : getObject(*e)) {
StringSet ss; StringSet ss;
flatten(storePathsJson, ss); flatten(storePathsJson, ss);

View file

@ -50,3 +50,16 @@ expectStderr 0 nix-instantiate --expr "$hackyExpr" --eval --strict | grepQuiet "
# Check it works with the expected structured attrs # Check it works with the expected structured attrs
hacky=$(nix-instantiate --expr "$hackyExpr") hacky=$(nix-instantiate --expr "$hackyExpr")
nix derivation show "$hacky" | jq --exit-status '.derivations."'"$(basename "$hacky")"'".structuredAttrs | . == {"a": 1}' nix derivation show "$hacky" | jq --exit-status '.derivations."'"$(basename "$hacky")"'".structuredAttrs | . == {"a": 1}'
# Test warning for non-object exportReferencesGraph in structured attrs
# shellcheck disable=SC2016
expectStderr 0 nix-build --expr '
with import ./config.nix;
mkDerivation {
name = "export-graph-non-object";
__structuredAttrs = true;
exportReferencesGraph = [ "foo" "bar" ];
builder = "/bin/sh";
args = ["-c" "echo foo > ${builtins.placeholder "out"}"];
}
' | grepQuiet "warning:.*exportReferencesGraph.*not a JSON object"