[Nix-dev] rec {} // {} ?
Eelco Dolstra
eelco at cs.uu.nl
Wed Jun 6 10:25:12 CEST 2007
Marc Weber wrote:
> let a = rec { x=y;.. }; in
> let b = rce { y=x;.. }; in
> a // b;
>
> Should a // b be rec as well ?
"rec" is basically desugared to a normal attribute set by substituting the rec
inside itself. So
a = rec { x = y; y = 123; ... }
= { x = (rec { x = y; y = 123; ...}).y; y = 123; ... }
So you can update the y attribute, but other attributes will still get the old
value of y.
Note that if this weren't the case, you would get very weird scoping. In your
example
let a = rec { x=y;.. }; in
"y" would presumably refer to some "y" in the surrounding scope, but if you then do
let b = rec { y=x;.. }; in
a // b;
it would suddenly refer to the "y" in "b". This would break equational reasoning.
BTW, Martin and I have thought about this in the past, since it *would* be very
nice to be able to update a rec in this way. For instance, right now you can't
easily update something in all-packages.nix, say, update the "gtk" attribute
with the // operator and have all other packages build against the new gtk. But
we couldn't really come up with a semantically clean way to do this.
--
Eelco Dolstra | http://www.cs.uu.nl/~eelco
More information about the nix-dev
mailing list