2020-07-22 21:17:48 +00:00
|
|
|
|
# Operators
|
|
|
|
|
|
2022-12-22 21:10:11 +00:00
|
|
|
|
## Attribute selection
|
2022-12-22 20:21:26 +00:00
|
|
|
|
|
|
|
|
|
> *e* `.` *attrpath* \[ `or` *def* \]
|
|
|
|
|
|
2022-12-22 21:10:11 +00:00
|
|
|
|
Select the attribute denoted by attribute path *attrpath* from attribute set *e*.
|
|
|
|
|
An attribute path is a dot-separated list of attribute names.
|
|
|
|
|
If the attribute doesn’t exist, return *def* if provided, otherwise abort evaluation.
|
2022-12-22 20:21:26 +00:00
|
|
|
|
|
|
|
|
|
Associativity: none
|
|
|
|
|
|
|
|
|
|
Precedence: 1
|
|
|
|
|
|
2022-12-22 21:10:11 +00:00
|
|
|
|
## Function application
|
2022-12-22 20:21:26 +00:00
|
|
|
|
|
2022-12-22 21:10:11 +00:00
|
|
|
|
> *f* *e*
|
2022-12-22 20:21:26 +00:00
|
|
|
|
|
2022-12-22 21:10:11 +00:00
|
|
|
|
Call function *f* with argument *e*.
|
2022-12-22 20:21:26 +00:00
|
|
|
|
|
|
|
|
|
Associativity: left
|
|
|
|
|
|
|
|
|
|
Precedence: 2
|
|
|
|
|
|
2022-12-22 21:10:11 +00:00
|
|
|
|
## Arithmetic negation
|
2022-12-22 20:21:26 +00:00
|
|
|
|
|
|
|
|
|
> `-` *e*
|
|
|
|
|
|
|
|
|
|
Associativity: none
|
|
|
|
|
|
|
|
|
|
Precedence: 3
|
|
|
|
|
|
2022-12-22 21:10:11 +00:00
|
|
|
|
## Has attribute
|
2022-12-22 20:21:26 +00:00
|
|
|
|
|
|
|
|
|
> *e* `?` *attrpath*
|
|
|
|
|
|
|
|
|
|
Test whether set *e* contains the attribute denoted by *attrpath*; return `true` or `false`.
|
|
|
|
|
|
|
|
|
|
Associativity: none
|
|
|
|
|
|
|
|
|
|
Precedence: 4
|
|
|
|
|
|
2022-12-22 21:10:11 +00:00
|
|
|
|
## List concatenation
|
2022-12-22 20:21:26 +00:00
|
|
|
|
|
|
|
|
|
> *e1* `++` *e2*
|
|
|
|
|
|
2022-12-22 21:10:11 +00:00
|
|
|
|
Concatenate lists *e1* and *e2*.
|
2022-12-22 20:21:26 +00:00
|
|
|
|
|
|
|
|
|
Associativity: right
|
|
|
|
|
|
|
|
|
|
Precedence: 5
|
|
|
|
|
|
|
|
|
|
## Multiplication
|
|
|
|
|
|
|
|
|
|
> *e1* `*` *e2*,
|
|
|
|
|
|
2022-12-22 21:10:11 +00:00
|
|
|
|
Multiply numbers *e1* and *e2*.
|
2022-12-22 20:21:26 +00:00
|
|
|
|
|
|
|
|
|
Associativity: left
|
|
|
|
|
|
|
|
|
|
Precedence: 6
|
|
|
|
|
|
|
|
|
|
## Division
|
|
|
|
|
|
|
|
|
|
> *e1* `/` *e2*
|
|
|
|
|
|
2022-12-22 21:10:11 +00:00
|
|
|
|
Divide numbers *e1* and *e2*.
|
2022-12-22 20:21:26 +00:00
|
|
|
|
|
|
|
|
|
Associativity: left
|
|
|
|
|
|
|
|
|
|
Precedence: 6
|
|
|
|
|
|
2022-12-22 21:11:17 +00:00
|
|
|
|
## Subtraction
|
2022-12-22 20:21:26 +00:00
|
|
|
|
|
2022-12-22 21:11:17 +00:00
|
|
|
|
> *e1* `-` *e2*
|
2022-12-22 20:21:26 +00:00
|
|
|
|
|
2022-12-22 21:11:17 +00:00
|
|
|
|
Subtract numbers *e2* from *e1*.
|
2022-12-22 20:21:26 +00:00
|
|
|
|
|
|
|
|
|
Associativity: left
|
|
|
|
|
|
|
|
|
|
Precedence: 7
|
|
|
|
|
|
2022-12-22 21:11:17 +00:00
|
|
|
|
## Addition
|
2022-12-22 20:21:26 +00:00
|
|
|
|
|
2022-12-22 21:11:17 +00:00
|
|
|
|
> *e1* `+` *e2*
|
2022-12-22 20:21:26 +00:00
|
|
|
|
|
2022-12-22 21:11:17 +00:00
|
|
|
|
Add numbers *e1* and *e2*.
|
2022-12-22 20:21:26 +00:00
|
|
|
|
|
|
|
|
|
Associativity: left
|
|
|
|
|
|
|
|
|
|
Precedence: 7
|
|
|
|
|
|
2022-12-22 21:10:11 +00:00
|
|
|
|
## String concatenation
|
2022-12-22 20:21:26 +00:00
|
|
|
|
|
|
|
|
|
> *string1* `+` *string2*
|
|
|
|
|
|
2022-12-22 21:10:11 +00:00
|
|
|
|
Concatenate *string1* and *string1* and merge their string contexts.
|
2022-12-22 20:21:26 +00:00
|
|
|
|
|
|
|
|
|
Associativity: left
|
|
|
|
|
|
|
|
|
|
Precedence: 7
|
|
|
|
|
|
2022-12-22 21:11:17 +00: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 21:10:11 +00:00
|
|
|
|
## Logical negation (`NOT`)
|
2022-12-22 20:21:26 +00:00
|
|
|
|
|
|
|
|
|
> `!` *e*
|
|
|
|
|
|
2022-12-22 21:10:11 +00:00
|
|
|
|
Negate the Boolean value *e*.
|
2022-12-22 20:21:26 +00:00
|
|
|
|
|
|
|
|
|
Associativity: none
|
|
|
|
|
|
|
|
|
|
Precedence: 8
|
|
|
|
|
|
2022-12-22 21:10:11 +00:00
|
|
|
|
## Merge attribute sets
|
2022-12-22 20:21:26 +00:00
|
|
|
|
|
|
|
|
|
> *e1* `//` *e2*
|
|
|
|
|
|
2022-12-22 21:10:11 +00:00
|
|
|
|
Return a set consisting of all the attributes in *e1* and *e2*.
|
|
|
|
|
If an attribute name is present in both, the attribute value from the former is taken.
|
2022-12-22 20:21:26 +00:00
|
|
|
|
|
|
|
|
|
Associativity: right
|
|
|
|
|
|
|
|
|
|
Precedence: 9
|
|
|
|
|
|
2022-12-22 21:10:11 +00:00
|
|
|
|
## Less than
|
2022-12-22 20:21:26 +00:00
|
|
|
|
|
|
|
|
|
> *e1* `<` *e2*,
|
|
|
|
|
|
2022-12-22 21:10:11 +00: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 20:21:26 +00:00
|
|
|
|
|
|
|
|
|
Associativity: none
|
|
|
|
|
|
|
|
|
|
Precedence: 10
|
|
|
|
|
|
2022-12-22 21:10:11 +00:00
|
|
|
|
## Less than or equal to
|
2022-12-22 20:21:26 +00:00
|
|
|
|
|
|
|
|
|
> *e1* `<=` *e2*
|
|
|
|
|
|
2022-12-22 21:10:11 +00: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 20:21:26 +00:00
|
|
|
|
|
|
|
|
|
Associativity: none
|
|
|
|
|
|
|
|
|
|
Precedence: 10
|
|
|
|
|
|
2022-12-22 21:10:11 +00:00
|
|
|
|
## Greater than
|
2022-12-22 20:21:26 +00:00
|
|
|
|
|
|
|
|
|
> *e1* `>` *e2*
|
|
|
|
|
|
2022-12-22 21:10:11 +00: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 20:21:26 +00:00
|
|
|
|
|
|
|
|
|
Associativity: none
|
|
|
|
|
|
|
|
|
|
Precedence: 10
|
|
|
|
|
|
2022-12-22 21:10:11 +00:00
|
|
|
|
## Greater than or equal to
|
2022-12-22 20:21:26 +00:00
|
|
|
|
|
|
|
|
|
> *e1* `>=` *e2*
|
|
|
|
|
|
2022-12-22 21:10:11 +00: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 20:21:26 +00:00
|
|
|
|
|
|
|
|
|
Associativity: none
|
|
|
|
|
|
|
|
|
|
Precedence: 10
|
|
|
|
|
|
|
|
|
|
## Equality
|
|
|
|
|
|
|
|
|
|
> *e1* `==` *e2*
|
|
|
|
|
|
2022-12-22 21:10:11 +00:00
|
|
|
|
Check *e1* and *e2* for equality.
|
|
|
|
|
|
|
|
|
|
- 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 20:21:26 +00:00
|
|
|
|
|
|
|
|
|
Associativity: none
|
|
|
|
|
|
|
|
|
|
Precedence: 11
|
|
|
|
|
|
|
|
|
|
## Inequality
|
|
|
|
|
|
|
|
|
|
> *e1* `!=` *e2*
|
|
|
|
|
|
2022-12-22 21:10:11 +00:00
|
|
|
|
Equivalent to `! (`*e1* `==` *e2* `)`
|
2022-12-22 20:21:26 +00:00
|
|
|
|
|
|
|
|
|
Associativity: none
|
|
|
|
|
|
|
|
|
|
Precedence: 11
|
|
|
|
|
|
2022-12-22 21:10:11 +00:00
|
|
|
|
## Logical conjunction (`AND`)
|
2022-12-22 20:21:26 +00:00
|
|
|
|
|
|
|
|
|
> *e1* `&&` *e2*
|
|
|
|
|
|
2022-12-22 21:10:11 +00:00
|
|
|
|
Return `true` if and only if both `e1` and `e2` evaluate to `true`, otherwise `false`.
|
2022-12-22 20:21:26 +00:00
|
|
|
|
|
|
|
|
|
Associativity: left
|
|
|
|
|
|
|
|
|
|
Precedence: 12
|
|
|
|
|
|
2022-12-22 21:10:11 +00:00
|
|
|
|
## Logical disjunction (`OR`)
|
2022-12-22 20:21:26 +00:00
|
|
|
|
|
2022-12-22 21:10:11 +00:00
|
|
|
|
> *e1* `||` *e2*
|
2022-12-22 20:21:26 +00:00
|
|
|
|
|
2022-12-22 21:10:11 +00:00
|
|
|
|
Return `true` if at least `e1` or `e2` evaluate to `true`, otherwise `false`.
|
2022-12-22 20:21:26 +00:00
|
|
|
|
|
|
|
|
|
Associativity: left
|
|
|
|
|
|
|
|
|
|
Precedence: 13
|
|
|
|
|
|
2022-12-22 21:10:11 +00:00
|
|
|
|
## Logical implication
|
2022-12-22 20:21:26 +00:00
|
|
|
|
|
2022-12-22 21:10:11 +00:00
|
|
|
|
> *e1* `->` *e2*
|
2022-12-22 20:21:26 +00:00
|
|
|
|
|
2022-12-22 21:10:11 +00:00
|
|
|
|
Return `false` if *e1* evaluates to `true` and *e2* evaluates to `false`, otherwise `true`.
|
|
|
|
|
|
|
|
|
|
Equivalent to `!`*e1* `||` *e2*.
|
2022-12-22 20:21:26 +00:00
|
|
|
|
|
|
|
|
|
Associativity: none
|
|
|
|
|
|
|
|
|
|
Precedence: 14
|