nix-book/source/nix-language/inherit.adoc
Amy de Buitléir 3d8f0e2b8b initial commit
2025-10-12 15:55:01 +01:00

30 lines
512 B
Text

= Inherit
The `inherit` keyword causes the specified attributes to be bound to
whatever variables with the same name happen to be in scope.
When defining a set or in a let-expression it is often convenient to copy variables
from the surrounding lexical scope (e.g., when you want to propagate attributes).
This can be shortened using `inherit`.
For instance,
[source,nix]
....
let x = 123; in
{
inherit x;
y = 456;
}
....
is equivalent to
[source,nix]
....
let x = 123; in
{
x = x;
y = 456;
}
....