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
|
|
|
|
|
2022-12-22 21:25:37 +00:00
|
|
|
|
> *attrset* `.` *attrpath* \[ `or` *value* \]
|
2022-12-22 20:21:26 +00:00
|
|
|
|
|
2022-12-23 07:58:19 +00:00
|
|
|
|
Select the attribute denoted by attribute path *attrpath* from [attribute set] *attrset*.
|
2022-12-22 21:10:11 +00:00
|
|
|
|
An attribute path is a dot-separated list of attribute names.
|
2022-12-22 21:25:37 +00:00
|
|
|
|
If the attribute doesn’t exist, return *value* 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:25:37 +00:00
|
|
|
|
> *f* *a*
|
2022-12-22 20:21:26 +00:00
|
|
|
|
|
2022-12-23 07:58:19 +00:00
|
|
|
|
Call [function] *f* with argument *a*.
|
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
|
|
|
|
|
2022-12-22 21:25:37 +00:00
|
|
|
|
> `-` *n*
|
|
|
|
|
|
2022-12-23 07:58:19 +00:00
|
|
|
|
Flip the sign of the [number] *n*.
|
2022-12-22 20:21:26 +00:00
|
|
|
|
|
|
|
|
|
Associativity: none
|
|
|
|
|
|
|
|
|
|
Precedence: 3
|
|
|
|
|
|
2022-12-22 21:10:11 +00:00
|
|
|
|
## Has attribute
|
2022-12-22 20:21:26 +00:00
|
|
|
|
|
2022-12-22 21:25:37 +00:00
|
|
|
|
> *attrset* `?` *attrpath*
|
2022-12-22 20:21:26 +00:00
|
|
|
|
|
2022-12-23 07:58:19 +00:00
|
|
|
|
Test whether [attribute set] *attrset* contains the attribute denoted by *attrpath*; return `true` or `false`.
|
2022-12-22 20:21:26 +00:00
|
|
|
|
|
|
|
|
|
Associativity: none
|
|
|
|
|
|
|
|
|
|
Precedence: 4
|
|
|
|
|
|
2022-12-22 21:10:11 +00:00
|
|
|
|
## List concatenation
|
2022-12-22 20:21:26 +00:00
|
|
|
|
|
2022-12-22 21:25:37 +00:00
|
|
|
|
> *list1* `++` *list2*
|
2022-12-22 20:21:26 +00:00
|
|
|
|
|
2022-12-23 07:58:19 +00:00
|
|
|
|
Concatenate [list]s *list1* and *list2*.
|
2022-12-22 20:21:26 +00:00
|
|
|
|
|
|
|
|
|
Associativity: right
|
|
|
|
|
|
|
|
|
|
Precedence: 5
|
|
|
|
|
|
|
|
|
|
## Multiplication
|
|
|
|
|
|
2022-12-22 21:25:37 +00:00
|
|
|
|
> *n1* `*` *n2*,
|
2022-12-22 20:21:26 +00:00
|
|
|
|
|
2022-12-23 07:58:19 +00:00
|
|
|
|
Multiply [number]s *n1* and *n2*.
|
2022-12-22 20:21:26 +00:00
|
|
|
|
|
|
|
|
|
Associativity: left
|
|
|
|
|
|
|
|
|
|
Precedence: 6
|
|
|
|
|
|
|
|
|
|
## Division
|
|
|
|
|
|
2022-12-22 21:25:37 +00:00
|
|
|
|
> *n1* `/` *n2*
|
2022-12-22 20:21:26 +00:00
|
|
|
|
|
2022-12-23 07:58:19 +00:00
|
|
|
|
Divide [number]s *n1* and *n2*.
|
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:25:37 +00:00
|
|
|
|
> *n1* `-` *n2*
|
2022-12-22 20:21:26 +00:00
|
|
|
|
|
2022-12-23 07:58:19 +00:00
|
|
|
|
Subtract [number] *n2* from *n1*.
|
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:25:37 +00:00
|
|
|
|
> *n1* `+` *n2*
|
2022-12-22 20:21:26 +00:00
|
|
|
|
|
2022-12-23 07:58:19 +00:00
|
|
|
|
Add [number]s *n1* and *n2*.
|
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-23 07:58:19 +00:00
|
|
|
|
Concatenate two [string]s 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*
|
|
|
|
|
|
2022-12-23 07:58:19 +00:00
|
|
|
|
Concatenate two [path]s.
|
2022-12-22 21:11:17 +00:00
|
|
|
|
The result is a path.
|
|
|
|
|
|
|
|
|
|
## Path and string concatenation
|
|
|
|
|
|
|
|
|
|
> *path* `+` *string*
|
|
|
|
|
|
2022-12-23 07:58:19 +00:00
|
|
|
|
Concatenate *[path]* with *[string]*.
|
2022-12-22 21:11:17 +00:00
|
|
|
|
The result is a path.
|
|
|
|
|
|
|
|
|
|
> **Note**
|
|
|
|
|
>
|
2022-12-23 07:58:19 +00:00
|
|
|
|
> The string must not have a string context that refers to a [store path].
|
2022-12-22 21:11:17 +00:00
|
|
|
|
|
|
|
|
|
Associativity: left
|
|
|
|
|
|
|
|
|
|
Precedence: 7
|
|
|
|
|
|
|
|
|
|
## String and path concatenation
|
|
|
|
|
|
|
|
|
|
> *string* `+` *path*
|
|
|
|
|
|
2022-12-23 07:58:19 +00:00
|
|
|
|
Concatenate *[string]* with *[path]*.
|
2022-12-22 21:11:17 +00:00
|
|
|
|
The result is a string.
|
|
|
|
|
|
|
|
|
|
> **Important**
|
|
|
|
|
>
|
2022-12-23 07:58:19 +00:00
|
|
|
|
> 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].
|
2022-12-22 21:11:17 +00:00
|
|
|
|
|
|
|
|
|
Associativity: left
|
|
|
|
|
|
|
|
|
|
Precedence: 7
|
|
|
|
|
|
2022-12-22 21:10:11 +00:00
|
|
|
|
## Logical negation (`NOT`)
|
2022-12-22 20:21:26 +00:00
|
|
|
|
|
2022-12-22 21:25:37 +00:00
|
|
|
|
> `!` *b*
|
2022-12-22 20:21:26 +00:00
|
|
|
|
|
2022-12-23 07:58:19 +00:00
|
|
|
|
Negate the [Boolean] value *b*.
|
2022-12-22 20:21:26 +00:00
|
|
|
|
|
|
|
|
|
Associativity: none
|
|
|
|
|
|
|
|
|
|
Precedence: 8
|
|
|
|
|
|
2022-12-22 21:25:37 +00:00
|
|
|
|
## Update
|
|
|
|
|
|
|
|
|
|
> *attrset1* `//` *attrset1*
|
2022-12-22 20:21:26 +00:00
|
|
|
|
|
2022-12-23 07:58:19 +00:00
|
|
|
|
Update [attribute set] *attrset1* with names and values from *attrset2*.
|
2022-12-22 20:21:26 +00:00
|
|
|
|
|
2022-12-22 21:25:37 +00:00
|
|
|
|
The returned attribute set will have of all the attributes in *e1* and *e2*.
|
2022-12-22 21:10:11 +00:00
|
|
|
|
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:25:37 +00:00
|
|
|
|
## Comparison
|
2022-12-22 20:21:26 +00:00
|
|
|
|
|
2022-12-23 07:58:19 +00:00
|
|
|
|
- Arithmetic comparison for [number]s
|
|
|
|
|
- Lexicographic comparison for [string]s and [path]s
|
|
|
|
|
- Lexicographic comparison for [list]s:
|
2022-12-22 21:10:11 +00:00
|
|
|
|
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:25:37 +00:00
|
|
|
|
### Less than
|
2022-12-22 20:21:26 +00:00
|
|
|
|
|
2022-12-22 21:25:37 +00:00
|
|
|
|
> *e1* `<` *e2*,
|
2022-12-22 20:21:26 +00:00
|
|
|
|
|
2022-12-22 21:25:37 +00:00
|
|
|
|
### Less than or equal to
|
2022-12-22 20:21:26 +00:00
|
|
|
|
|
2022-12-22 21:25:37 +00:00
|
|
|
|
> *e1* `<=` *e2*
|
2022-12-22 20:21:26 +00:00
|
|
|
|
|
2022-12-22 21:25:37 +00:00
|
|
|
|
### Greater than
|
2022-12-22 20:21:26 +00:00
|
|
|
|
|
|
|
|
|
> *e1* `>` *e2*
|
|
|
|
|
|
2022-12-22 21:25:37 +00:00
|
|
|
|
### Greater than or equal to
|
2022-12-22 20:21:26 +00:00
|
|
|
|
|
|
|
|
|
> *e1* `>=` *e2*
|
|
|
|
|
|
|
|
|
|
## Equality
|
|
|
|
|
|
|
|
|
|
> *e1* `==` *e2*
|
|
|
|
|
|
2022-12-22 21:25:37 +00:00
|
|
|
|
Check expressions *e1* and *e2* for value equality.
|
2022-12-22 21:10:11 +00:00
|
|
|
|
|
2022-12-23 07:58:19 +00:00
|
|
|
|
- [Attribute sets][attribute set] and [list]s are compared recursively, and therefore are fully evaluated.
|
|
|
|
|
- Comparison of [function]s always returns `false`.
|
2022-12-22 21:10:11 +00:00
|
|
|
|
- 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
|
|
|
|
|
2022-12-22 21:25:37 +00:00
|
|
|
|
> *b1* `&&` *b2*
|
2022-12-22 20:21:26 +00:00
|
|
|
|
|
2022-12-22 21:25:37 +00:00
|
|
|
|
Return `true` if and only if both `b1` and `b2` 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:25:37 +00:00
|
|
|
|
> *b1* `||` *b2*
|
2022-12-22 20:21:26 +00:00
|
|
|
|
|
2022-12-22 21:25:37 +00:00
|
|
|
|
Return `true` if at least one of `b1` or `b2` 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:25:37 +00:00
|
|
|
|
> *b1* `->` *b2*
|
2022-12-22 20:21:26 +00:00
|
|
|
|
|
2022-12-22 21:25:37 +00:00
|
|
|
|
Return `false` if *b1* evaluates to `true` and *b2* evaluates to `false`, otherwise `true`.
|
2022-12-22 21:10:11 +00:00
|
|
|
|
|
2022-12-22 21:25:37 +00:00
|
|
|
|
Equivalent to `!`*b1* `||` *b2*.
|
2022-12-22 20:21:26 +00:00
|
|
|
|
|
|
|
|
|
Associativity: none
|
|
|
|
|
|
|
|
|
|
Precedence: 14
|
2022-12-23 07:58:19 +00:00
|
|
|
|
|
|
|
|
|
[string]: ./values.md#type-string
|
|
|
|
|
[path]: ./values.md#type-path
|
|
|
|
|
[number]: ./values.md#type-number
|
|
|
|
|
[Boolean]: ./values.md#type-boolean
|
|
|
|
|
[list]: ./values.md#list
|
|
|
|
|
[attribute set]: ./values.md#attribute-set
|
|
|
|
|
[function]: ./constructs.md#functions
|
|
|
|
|
[store path]: ../glossary.md#gloss-store-path
|
|
|
|
|
[store]: ../glossary.md#gloss-store
|