Nix Language Quirks: Difference between revisions
m Grammar |
Add quirk regarding conditional key names defining attribute set entries |
||
| Line 198: | Line 198: | ||
nix-repl> { ${null} = "value"; key = "value2"; } | nix-repl> { ${null} = "value"; key = "value2"; } | ||
{ key = "value2"; } | { key = "value2"; } | ||
</syntaxHighlight> | |||
== Dynamic key names can conditionally assign attribute set entries == | |||
Dynamic key names with conditional expressions can be used to conditionally include or exclude attribute set entries | |||
<syntaxHighlight lang=nix> | |||
nix-repl> { ${if true then "foo" else null} = "bar"; } | |||
{ foo = "bar"; } | |||
nix-repl> { ${if false then "foo" else null} = "bar"; } | |||
{ } | |||
</syntaxHighlight> | </syntaxHighlight> | ||