5.9 KiB
Nix Language
The Nix language is a pure, lazy, functional language. Purity means that operations in the language don't have side-effects (for instance, there is no variable assignment). Laziness means that arguments to functions are evaluated only when they are needed. Functional means that functions are “normal” values that can be passed around and manipulated in interesting ways. The language is not a full-featured, general purpose language. Its main job is to describe packages, compositions of packages, and the variability within packages.
This section presents the various features of the language.
Overview
This is an incomplete overview of language features, by example.
Example | Description |
---|---|
Basic values |
|
|
A string |
|
A multi-line string. Strips common prefixed whitespace. Evaluates to |
|
String interpolation (expands to |
|
Booleans |
|
Null value |
|
An integer |
|
A floating point number |
|
An absolute path |
|
A path relative to the file containing this Nix expression |
|
A home path. Evaluates to the |
Search path. Value determined by |
|
Compound values |
|
|
A set with attributes named |
|
A nested set, equivalent to |
|
A recursive set, equivalent to |
|
Lists with three elements. |
Operators |
|
|
String concatenation |
|
Integer addition |
|
Equality test (evaluates to |
|
Inequality test (evaluates to |
|
Boolean negation |
|
Attribute selection (evaluates to |
|
Attribute selection with default (evaluates to |
|
Merge two sets (attributes in the right-hand set taking precedence) |
Control structures |
|
|
Conditional expression |
|
Assertion check (evaluates to |
|
Variable definition |
|
Add all attributes from the given set to the scope (evaluates to |
Functions (lambdas) |
|
|
A function that expects an integer and returns it increased by 1 |
|
Curried function, equivalent to |
|
A function call (evaluates to 101) |
|
A function bound to a variable and subsequently called by name (evaluates to 103) |
|
A function that expects a set with required attributes |
|
A function that expects a set with required attribute |
|
A function that expects a set with required attributes |
|
A function that expects a set with required attributes |
Built-in functions |
|
|
Load and return Nix expression in given file |
|
Apply a function to every element of a list (evaluates to |