2020-07-22 17:17:48 -04:00
|
|
|
|
# Operators
|
|
|
|
|
|
2022-12-22 16:10:11 -05:00
|
|
|
|
## Attribute selection
|
2022-12-22 15:21:26 -05:00
|
|
|
|
|
2022-12-22 16:25:37 -05:00
|
|
|
|
> *attrset* `.` *attrpath* \[ `or` *value* \]
|
2022-12-22 15:21:26 -05:00
|
|
|
|
|
2022-12-22 16:25:37 -05:00
|
|
|
|
Select the attribute denoted by attribute path *attrpath* from attribute set *attrset*.
|
2022-12-22 16:10:11 -05:00
|
|
|
|
An attribute path is a dot-separated list of attribute names.
|
2022-12-22 16:25:37 -05:00
|
|
|
|
If the attribute doesn’t exist, return *value* if provided, otherwise abort evaluation.
|
2022-12-22 15:21:26 -05:00
|
|
|
|
|
|
|
|
|
Associativity: none
|
|
|
|
|
|
|
|
|
|
Precedence: 1
|
|
|
|
|
|
2022-12-22 16:10:11 -05:00
|
|
|
|
## Function application
|
2022-12-22 15:21:26 -05:00
|
|
|
|
|
2022-12-22 16:25:37 -05:00
|
|
|
|
> *f* *a*
|
2022-12-22 15:21:26 -05:00
|
|
|
|
|
2022-12-22 16:25:37 -05:00
|
|
|
|
Call function *f* with argument *a*.
|
2022-12-22 15:21:26 -05:00
|
|
|
|
|
|
|
|
|
Associativity: left
|
|
|
|
|
|
|
|
|
|
Precedence: 2
|
|
|
|
|
|
2022-12-22 16:10:11 -05:00
|
|
|
|
## Arithmetic negation
|
2022-12-22 15:21:26 -05:00
|
|
|
|
|
2022-12-22 16:25:37 -05:00
|
|
|
|
> `-` *n*
|
|
|
|
|
|
|
|
|
|
Flip the sign of the number *n*.
|
2022-12-22 15:21:26 -05:00
|
|
|
|
|
|
|
|
|
Associativity: none
|
|
|
|
|
|
|
|
|
|
Precedence: 3
|
|
|
|
|
|
2022-12-22 16:10:11 -05:00
|
|
|
|
## Has attribute
|
2022-12-22 15:21:26 -05:00
|
|
|
|
|
2022-12-22 16:25:37 -05:00
|
|
|
|
> *attrset* `?` *attrpath*
|
2022-12-22 15:21:26 -05:00
|
|
|
|
|
2022-12-22 16:25:37 -05:00
|
|
|
|
Test whether attribute set *attrset* contains the attribute denoted by *attrpath*; return `true` or `false`.
|
2022-12-22 15:21:26 -05:00
|
|
|
|
|
|
|
|
|
Associativity: none
|
|
|
|
|
|
|
|
|
|
Precedence: 4
|
|
|
|
|
|
2022-12-22 16:10:11 -05:00
|
|
|
|
## List concatenation
|
2022-12-22 15:21:26 -05:00
|
|
|
|
|
2022-12-22 16:25:37 -05:00
|
|
|
|
> *list1* `++` *list2*
|
2022-12-22 15:21:26 -05:00
|
|
|
|
|
2022-12-22 16:25:37 -05:00
|
|
|
|
Concatenate lists *list1* and *list2*.
|
2022-12-22 15:21:26 -05:00
|
|
|
|
|
|
|
|
|
Associativity: right
|
|
|
|
|
|
|
|
|
|
Precedence: 5
|
|
|
|
|
|
|
|
|
|
## Multiplication
|
|
|
|
|
|
2022-12-22 16:25:37 -05:00
|
|
|
|
> *n1* `*` *n2*,
|
2022-12-22 15:21:26 -05:00
|
|
|
|
|
2022-12-22 16:25:37 -05:00
|
|
|
|
Multiply numbers *n1* and *n2*.
|
2022-12-22 15:21:26 -05:00
|
|
|
|
|
|
|
|
|
Associativity: left
|
|
|
|
|
|
|
|
|
|
Precedence: 6
|
|
|
|
|
|
|
|
|
|
## Division
|
|
|
|
|
|
2022-12-22 16:25:37 -05:00
|
|
|
|
> *n1* `/` *n2*
|
2022-12-22 15:21:26 -05:00
|
|
|
|
|
2022-12-22 16:25:37 -05:00
|
|
|
|
Divide numbers *n1* and *n2*.
|
2022-12-22 15:21:26 -05:00
|
|
|
|
|
|
|
|
|
Associativity: left
|
|
|
|
|
|
|
|
|
|
Precedence: 6
|
|
|
|
|
|
2022-12-22 16:11:17 -05:00
|
|
|
|
## Subtraction
|
2022-12-22 15:21:26 -05:00
|
|
|
|
|
2022-12-22 16:25:37 -05:00
|
|
|
|
> *n1* `-` *n2*
|
2022-12-22 15:21:26 -05:00
|
|
|
|
|
2022-12-22 16:25:37 -05:00
|
|
|
|
Subtract numbers *n2* from *n1*.
|
2022-12-22 15:21:26 -05:00
|
|
|
|
|
|
|
|
|
Associativity: left
|
|
|
|
|
|
|
|
|
|
Precedence: 7
|
|
|
|
|
|
2022-12-22 16:11:17 -05:00
|
|
|
|
## Addition
|
2022-12-22 15:21:26 -05:00
|
|
|
|
|
2022-12-22 16:25:37 -05:00
|
|
|
|
> *n1* `+` *n2*
|
2022-12-22 15:21:26 -05:00
|
|
|
|
|
2022-12-22 16:25:37 -05:00
|
|
|
|
Add numbers *n1* and *n2*.
|
2022-12-22 15:21:26 -05:00
|
|
|
|
|
|
|
|
|
Associativity: left
|
|
|
|
|
|
|
|
|
|
Precedence: 7
|
|
|
|
|
|
2022-12-22 16:10:11 -05:00
|
|
|
|
## String concatenation
|
2022-12-22 15:21:26 -05:00
|
|
|
|
|
|
|
|
|
> *string1* `+` *string2*
|
|
|
|
|
|
2022-12-22 16:10:11 -05:00
|
|
|
|
Concatenate *string1* and *string1* and merge their string contexts.
|
2022-12-22 15:21:26 -05:00
|
|
|
|
|
|
|
|
|
Associativity: left
|
|
|
|
|
|
|
|
|
|
Precedence: 7
|
|
|
|
|
|
2022-12-22 16:11:17 -05:00
|
|
|
|
## Path concatenation
|
|
|
|
|
|
|
|
|
|
> *path1* `+` *path2*
|
|
|
|
|
|
|
|
|
|
Concatenate two paths.
|
|
|
|
|
The result is a path.
|
|
|
|
|
|
|
|
|
|
## Path and string concatenation
|
|
|
|
|
|
|
|
|
|
> *path* `+` *string*
|
|
|
|
|
|
|
|
|
|
Concatenate *path* with *string*.
|
|
|
|
|
The result is a path.
|
|
|
|
|
|
|
|
|
|
> **Note**
|
|
|
|
|
>
|
|
|
|
|
> The string must not have a string context that refers to a store path.
|
|
|
|
|
|
|
|
|
|
Associativity: left
|
|
|
|
|
|
|
|
|
|
Precedence: 7
|
|
|
|
|
|
|
|
|
|
## String and path concatenation
|
|
|
|
|
|
|
|
|
|
> *string* `+` *path*
|
|
|
|
|
|
|
|
|
|
Concatenate *string* with *path*.
|
|
|
|
|
The result is a string.
|
|
|
|
|
|
|
|
|
|
> **Important**
|
|
|
|
|
>
|
|
|
|
|
> The file or directory at *path* must exist and is copied to the store
|
|
|
|
|
> The path appears in the result as the corresponding store path.
|
|
|
|
|
|
|
|
|
|
Associativity: left
|
|
|
|
|
|
|
|
|
|
Precedence: 7
|
|
|
|
|
|
2022-12-22 16:10:11 -05:00
|
|
|
|
## Logical negation (`NOT`)
|
2022-12-22 15:21:26 -05:00
|
|
|
|
|
2022-12-22 16:25:37 -05:00
|
|
|
|
> `!` *b*
|
2022-12-22 15:21:26 -05:00
|
|
|
|
|
2022-12-22 16:25:37 -05:00
|
|
|
|
Negate the Boolean value *b*.
|
2022-12-22 15:21:26 -05:00
|
|
|
|
|
|
|
|
|
Associativity: none
|
|
|
|
|
|
|
|
|
|
Precedence: 8
|
|
|
|
|
|
2022-12-22 16:25:37 -05:00
|
|
|
|
## Update
|
|
|
|
|
|
|
|
|
|
> *attrset1* `//` *attrset1*
|
2022-12-22 15:21:26 -05:00
|
|
|
|
|
2022-12-22 16:25:37 -05:00
|
|
|
|
Update attribute set *attrset1* with names and values from *attrset2*.
|
2022-12-22 15:21:26 -05:00
|
|
|
|
|
2022-12-22 16:25:37 -05:00
|
|
|
|
The returned attribute set will have of all the attributes in *e1* and *e2*.
|
2022-12-22 16:10:11 -05:00
|
|
|
|
If an attribute name is present in both, the attribute value from the former is taken.
|
2022-12-22 15:21:26 -05:00
|
|
|
|
|
|
|
|
|
Associativity: right
|
|
|
|
|
|
|
|
|
|
Precedence: 9
|
|
|
|
|
|
2022-12-22 16:25:37 -05:00
|
|
|
|
## Comparison
|
2022-12-22 15:21:26 -05:00
|
|
|
|
|
2022-12-22 16:10:11 -05:00
|
|
|
|
- Arithmetic comparison for numbers
|
|
|
|
|
- Lexicographic comparison for strings and paths
|
|
|
|
|
- Lexicographic comparison for lists:
|
|
|
|
|
Elements at the same index in both lists are compared according to their type and skipped if they are equal.
|
2022-12-22 15:21:26 -05:00
|
|
|
|
|
|
|
|
|
Associativity: none
|
|
|
|
|
|
|
|
|
|
Precedence: 10
|
|
|
|
|
|
2022-12-22 16:25:37 -05:00
|
|
|
|
### Less than
|
2022-12-22 15:21:26 -05:00
|
|
|
|
|
2022-12-22 16:25:37 -05:00
|
|
|
|
> *e1* `<` *e2*,
|
2022-12-22 15:21:26 -05:00
|
|
|
|
|
2022-12-22 16:25:37 -05:00
|
|
|
|
### Less than or equal to
|
2022-12-22 15:21:26 -05:00
|
|
|
|
|
2022-12-22 16:25:37 -05:00
|
|
|
|
> *e1* `<=` *e2*
|
2022-12-22 15:21:26 -05:00
|
|
|
|
|
2022-12-22 16:25:37 -05:00
|
|
|
|
### Greater than
|
2022-12-22 15:21:26 -05:00
|
|
|
|
|
|
|
|
|
> *e1* `>` *e2*
|
|
|
|
|
|
2022-12-22 16:25:37 -05:00
|
|
|
|
### Greater than or equal to
|
2022-12-22 15:21:26 -05:00
|
|
|
|
|
|
|
|
|
> *e1* `>=` *e2*
|
|
|
|
|
|
|
|
|
|
## Equality
|
|
|
|
|
|
|
|
|
|
> *e1* `==` *e2*
|
|
|
|
|
|
2022-12-22 16:25:37 -05:00
|
|
|
|
Check expressions *e1* and *e2* for value equality.
|
2022-12-22 16:10:11 -05:00
|
|
|
|
|
|
|
|
|
- Attribute sets and lists are compared recursively, and therefore are fully evaluated.
|
|
|
|
|
- Comparison of functions always returns `false`.
|
|
|
|
|
- Integers are coerced to floating point numbers if compared to floating point numbers.
|
|
|
|
|
- Floating point numbers only differ up to a limited precision.
|
2022-12-22 15:21:26 -05:00
|
|
|
|
|
|
|
|
|
Associativity: none
|
|
|
|
|
|
|
|
|
|
Precedence: 11
|
|
|
|
|
|
|
|
|
|
## Inequality
|
|
|
|
|
|
|
|
|
|
> *e1* `!=` *e2*
|
|
|
|
|
|
2022-12-22 16:10:11 -05:00
|
|
|
|
Equivalent to `! (`*e1* `==` *e2* `)`
|
2022-12-22 15:21:26 -05:00
|
|
|
|
|
|
|
|
|
Associativity: none
|
|
|
|
|
|
|
|
|
|
Precedence: 11
|
|
|
|
|
|
2022-12-22 16:10:11 -05:00
|
|
|
|
## Logical conjunction (`AND`)
|
2022-12-22 15:21:26 -05:00
|
|
|
|
|
2022-12-22 16:25:37 -05:00
|
|
|
|
> *b1* `&&` *b2*
|
2022-12-22 15:21:26 -05:00
|
|
|
|
|
2022-12-22 16:25:37 -05:00
|
|
|
|
Return `true` if and only if both `b1` and `b2` evaluate to `true`, otherwise `false`.
|
2022-12-22 15:21:26 -05:00
|
|
|
|
|
|
|
|
|
Associativity: left
|
|
|
|
|
|
|
|
|
|
Precedence: 12
|
|
|
|
|
|
2022-12-22 16:10:11 -05:00
|
|
|
|
## Logical disjunction (`OR`)
|
2022-12-22 15:21:26 -05:00
|
|
|
|
|
2022-12-22 16:25:37 -05:00
|
|
|
|
> *b1* `||` *b2*
|
2022-12-22 15:21:26 -05:00
|
|
|
|
|
2022-12-22 16:25:37 -05:00
|
|
|
|
Return `true` if at least one of `b1` or `b2` evaluate to `true`, otherwise `false`.
|
2022-12-22 15:21:26 -05:00
|
|
|
|
|
|
|
|
|
Associativity: left
|
|
|
|
|
|
|
|
|
|
Precedence: 13
|
|
|
|
|
|
2022-12-22 16:10:11 -05:00
|
|
|
|
## Logical implication
|
2022-12-22 15:21:26 -05:00
|
|
|
|
|
2022-12-22 16:25:37 -05:00
|
|
|
|
> *b1* `->` *b2*
|
2022-12-22 15:21:26 -05:00
|
|
|
|
|
2022-12-22 16:25:37 -05:00
|
|
|
|
Return `false` if *b1* evaluates to `true` and *b2* evaluates to `false`, otherwise `true`.
|
2022-12-22 16:10:11 -05:00
|
|
|
|
|
2022-12-22 16:25:37 -05:00
|
|
|
|
Equivalent to `!`*b1* `||` *b2*.
|
2022-12-22 15:21:26 -05:00
|
|
|
|
|
|
|
|
|
Associativity: none
|
|
|
|
|
|
|
|
|
|
Precedence: 14
|