Skip to content

Commit a4713ed

Browse files
committed
Deprecate hacky way of making structured attrs
The method tested for in the previous commit is now deprecated.
1 parent 025f9e7 commit a4713ed

File tree

4 files changed

+7
-1
lines changed

4 files changed

+7
-1
lines changed

src/libexpr/eval.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ EvalState::EvalState(
212212
, sRight(symbols.create("right"))
213213
, sWrong(symbols.create("wrong"))
214214
, sStructuredAttrs(symbols.create("__structuredAttrs"))
215+
, sJson(symbols.create("__json"))
215216
, sAllowedReferences(symbols.create("allowedReferences"))
216217
, sAllowedRequisites(symbols.create("allowedRequisites"))
217218
, sDisallowedReferences(symbols.create("disallowedReferences"))

src/libexpr/include/nix/expr/eval.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ public:
213213
const Symbol sWith, sOutPath, sDrvPath, sType, sMeta, sName, sValue,
214214
sSystem, sOverrides, sOutputs, sOutputName, sIgnoreNulls,
215215
sFile, sLine, sColumn, sFunctor, sToString,
216-
sRight, sWrong, sStructuredAttrs,
216+
sRight, sWrong, sStructuredAttrs, sJson,
217217
sAllowedReferences, sAllowedRequisites, sDisallowedReferences, sDisallowedRequisites,
218218
sMaxSize, sMaxClosureSize,
219219
sBuilder, sArgs,

src/libexpr/primops.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1419,6 +1419,8 @@ static void derivationStrictInternal(
14191419
else if (i->name == state.sOutputHashMode) handleHashMode(s);
14201420
else if (i->name == state.sOutputs)
14211421
handleOutputs(tokenizeString<Strings>(s));
1422+
else if (i->name == state.sJson)
1423+
warn("In a derivation named '%s', setting structured attrs via '__json' is deprecated, and may be removed in a future version of Nix", drvName);
14221424
}
14231425

14241426
}

tests/functional/structured-attrs.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ test "$(<<<"$jsonOut" jq '.variables.outputs.value.out' -r)" = "$(<<<"$jsonOut"
4545

4646
hackyExpr='derivation { name = "a"; system = "foo"; builder = "/bin/sh"; __json = builtins.toJSON { a = 1; }; }'
4747

48+
# Check for deprecation message
49+
expectStderr 0 nix-instantiate --expr "$hackyExpr" --eval --strict | grepQuiet "In a derivation named 'a', setting structured attrs via '__json' is deprecated, and may be removed in a future version of Nix"
50+
4851
# Check it works with the expected structured attrs
4952
hacky=$(nix-instantiate --expr "$hackyExpr")
5053
nix derivation show "$hacky" | jq --exit-status '."'"$hacky"'".env.__json | fromjson | . == {"a": 1}'

0 commit comments

Comments
 (0)