[Nix-dev] [***SPAM***] Proposal: Conditional attribute syntax sugar
Shea Levy
shea at shealevy.com
Sat Jan 7 18:24:14 CET 2012
Hi all,
Fairly frequently (especially when trying to get packages to build on
non-Linux platforms without affecting the build for Linux), I find
myself wishing for easier syntax for conditionally-existent attributes.
Right now, we have to do something like
{
a = 1;
} // (if condition then { b = 2; } else {})
whereas I would prefer to write something like (I'm not wed to this syntax)
{
a = 1;
b ?= condition 2;
}
Which would just be syntactic sugar for the first. For a recursive
attribute set, I imagine it we could have desugaring like this:
rec {
a = 1;
b ?= condition a;
}
to
let
first = rec { a = 1; }
second = rec { b = first.a; }
in first // (if condition then second else {})
Thoughts?
More information about the nix-dev
mailing list