mirror of
https://codeberg.org/mhwombat/nix-book.git
synced 2026-01-11 00:02:37 +08:00
33 lines
553 B
Text
33 lines
553 B
Text
= Variables
|
|
|
|
You can declare variables in Nix and assign values to them.
|
|
// TODO explain that values are immutable.
|
|
|
|
[source]
|
|
....
|
|
nix-repl> a = 7
|
|
|
|
nix-repl> b = 3
|
|
|
|
nix-repl> a - b
|
|
4
|
|
....
|
|
|
|
[IMPORTANT]
|
|
====
|
|
As mentioned previously, omitting the spaces around operators can have unexpected results.
|
|
As Nix allows hyphens (`-`) in variable names,
|
|
`a-b` is interpreted as the name of a variable in the following example.
|
|
|
|
[source]
|
|
....
|
|
nix-repl> a-b
|
|
error: undefined variable 'a-b'
|
|
|
|
at «string»:1:1:
|
|
|
|
1| a-b
|
|
| ^
|
|
....
|
|
====
|
|
|