You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It is possible to inherit attributes from another set1. For example:
letx={a=1;b=2;}y={inherit(x)ab;}
in
y# evaluates to `{ a = 1; b = 2; }`
But since Nix does not have maximal laziness, inheriting from the result of a function call will evaluate the function for each inherited attribute. That is, evaluating the expression below:
It is possible to inherit attributes from another set1. For example:
But since Nix does not have maximal laziness, inheriting from the result of a function call will evaluate the function for each inherited attribute. That is, evaluating the expression below:
will evaluate
f 0
2 times (which can be checked withtrace
). This can be avoided with:In this case
f 0
will be evaluated only once because the result is saved in a variable.An exception to this is
import
. While the manual notes thatimport
is a regular function, result ofimport <path>
seems to be cached internally, so:Footnotes
https://nixos.org/manual/nix/unstable/language/constructs.html#inheriting-attributes ↩
The text was updated successfully, but these errors were encountered: