about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/libexpr/eval.cc10
-rw-r--r--tests/lang/eval-okay-null-dynamic-attrs.exp1
-rw-r--r--tests/lang/eval-okay-null-dynamic-attrs.nix1
3 files changed, 11 insertions, 1 deletions
diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc
index 350a4fbe141f..730b431cf255 100644
--- a/src/libexpr/eval.cc
+++ b/src/libexpr/eval.cc
@@ -642,7 +642,15 @@ void ExprAttrs::eval(EvalState & state, Env & env, Value & v)
     /* dynamic attrs apply *after* rec and __overrides */
     foreach (DynamicAttrDefs::iterator, i, dynamicAttrs) {
         Value nameVal;
-        i->nameExpr->eval(state, *dynamicEnv, nameVal);
+        assert(dynamic_cast<ExprConcatStrings *>(i->nameExpr));
+        ExprConcatStrings * nameExpr = static_cast<ExprConcatStrings *>(i->nameExpr);
+        if (nameExpr->es->size() == 1) {
+            nameExpr->es->front()->eval(state, *dynamicEnv, nameVal);
+            state.forceValue(nameVal);
+            if (nameVal.type == tNull)
+                continue;
+        }
+        nameExpr->eval(state, *dynamicEnv, nameVal);
         state.forceStringNoCtx(nameVal);
         Symbol nameSym = state.symbols.create(nameVal.string.s);
         Bindings::iterator j = v.attrs->find(nameSym);
diff --git a/tests/lang/eval-okay-null-dynamic-attrs.exp b/tests/lang/eval-okay-null-dynamic-attrs.exp
new file mode 100644
index 000000000000..27ba77ddaf61
--- /dev/null
+++ b/tests/lang/eval-okay-null-dynamic-attrs.exp
@@ -0,0 +1 @@
+true
diff --git a/tests/lang/eval-okay-null-dynamic-attrs.nix b/tests/lang/eval-okay-null-dynamic-attrs.nix
new file mode 100644
index 000000000000..b060c0bc9850
--- /dev/null
+++ b/tests/lang/eval-okay-null-dynamic-attrs.nix
@@ -0,0 +1 @@
+{ ${null} = true; } == {}