mirror of
https://codeberg.org/mhwombat/nix-book.git
synced 2026-01-09 07:17:28 +08:00
30 lines
512 B
Text
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;
|
|
}
|
|
....
|