From 1c63cf40019c5cb928bbd9eab5cd9aef6e77b03e Mon Sep 17 00:00:00 2001 From: John Ericson Date: Tue, 9 Dec 2025 13:02:46 -0500 Subject: [PATCH] Add warning for non-JSON-object `exportReferencesGraph` This will help users debug their mistakes. --- src/libstore/derivation-options.cc | 6 +++++- tests/functional/structured-attrs.sh | 13 +++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/libstore/derivation-options.cc b/src/libstore/derivation-options.cc index 2ead0c444..f4faca391 100644 --- a/src/libstore/derivation-options.cc +++ b/src/libstore/derivation-options.cc @@ -341,8 +341,12 @@ DerivationOptions derivationOptionsFromStructuredAttrs( if (parsed) { auto * e = optionalValueAt(parsed->structuredAttrs, "exportReferencesGraph"); - if (!e || !e->is_object()) + if (!e) 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)) { StringSet ss; flatten(storePathsJson, ss); diff --git a/tests/functional/structured-attrs.sh b/tests/functional/structured-attrs.sh index 01bdc10d1..a9077e938 100755 --- a/tests/functional/structured-attrs.sh +++ b/tests/functional/structured-attrs.sh @@ -50,3 +50,16 @@ expectStderr 0 nix-instantiate --expr "$hackyExpr" --eval --strict | grepQuiet " # Check it works with the expected structured attrs hacky=$(nix-instantiate --expr "$hackyExpr") 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"