Merge pull request #6845 from fricklerhandwerk/attrset

manual: set -> attribute set
This commit is contained in:
Eelco Dolstra 2022-07-28 16:55:03 +02:00 committed by GitHub
commit 86fcd4f692
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 11 deletions

View file

@ -33,7 +33,7 @@
- [Arguments and Variables](expressions/arguments-variables.md) - [Arguments and Variables](expressions/arguments-variables.md)
- [Building and Testing](expressions/simple-building-testing.md) - [Building and Testing](expressions/simple-building-testing.md)
- [Generic Builder Syntax](expressions/generic-builder.md) - [Generic Builder Syntax](expressions/generic-builder.md)
- [Writing Nix Expressions](expressions/expression-language.md) - [Nix Expression Language](expressions/expression-language.md)
- [Values](expressions/language-values.md) - [Values](expressions/language-values.md)
- [Language Constructs](expressions/language-constructs.md) - [Language Constructs](expressions/language-constructs.md)
- [Operators](expressions/language-operators.md) - [Operators](expressions/language-operators.md)

View file

@ -172,25 +172,27 @@ function and the fifth being a set.
Note that lists are only lazy in values, and they are strict in length. Note that lists are only lazy in values, and they are strict in length.
## Sets ## Attribute Sets
Sets are really the core of the language, since ultimately the Nix Attribute sets are collections of name-value-pairs (called *attributes*) enclosed in curly brackets (`{ }`).
language is all about creating derivations, which are really just sets
of attributes to be passed to build scripts.
Sets are just a list of name/value pairs (called *attributes*) enclosed Names and values are separated by an equal sign (`=`).
in curly brackets, where each value is an arbitrary expression Each value is an arbitrary expression terminated by a semicolon (`;`).
terminated by a semicolon. For example:
Attributes can appear in any order.
An attribute name may only occur once.
Example:
```nix ```nix
{ x = 123; {
x = 123;
text = "Hello"; text = "Hello";
y = f { bla = 456; }; y = f { bla = 456; };
} }
``` ```
This defines a set with attributes named `x`, `text`, `y`. The order of This defines a set with attributes named `x`, `text`, `y`.
the attributes is irrelevant. An attribute name may only occur once.
Attributes can be selected from a set using the `.` operator. For Attributes can be selected from a set using the `.` operator. For
instance, instance,