30 lines
647 B
Nix
30 lines
647 B
Nix
#inherit is shorthand for assigning the value of a name from an existing scope
|
|
#to the same name in a nested scope.
|
|
#It is for convenience to avoid repeating the same name multiple times.
|
|
let
|
|
x = 1;
|
|
y = 2;
|
|
in
|
|
{
|
|
inherit x y;
|
|
}
|
|
|
|
# the fragment ```inherit x y;``` is equivalent to:
|
|
# ``` x = x;y = y;
|
|
|
|
# It is also possible to inherit names from a specific attribute set with parentheses (inherit (...) ...).
|
|
#let
|
|
# a = { x = 1; y = 2; };
|
|
#in
|
|
#{
|
|
# inherit (a) x y;
|
|
#}
|
|
|
|
# The fragment
|
|
#inherit (a) x y;
|
|
# is equivalent to
|
|
#x = a.x; y = a.y;
|
|
# inherit also work inside ``let`` expressions.
|
|
#let
|
|
# inherit ({ x = 1; y = 2; }) x y;
|
|
#in [ x y ] |