[Nix-dev] Variable Assignment in Nix Expressions

Roger Qiu roger.qiu at polycademy.com
Mon Aug 18 11:21:29 CEST 2014


Hello,

How come the nix-repl allows a freestanding variable assignment, but the 
actual Nix expressions don't?

```
# allowed in nix-repl but not in normal nix
x = 5
```

```
# allowed in normal nix and nix-repl
let x = 5; in {}
```

Apparently this has something to do with the purity and lambda calculus. 
Assigning a variable is basically passing this variable into the 
function scope of the body of code (which is done in Nix as let + {} 
attributes). But wouldn't it be easier if we could have simpler variable 
assignment semantics and allow a straightforward x = 5 in a function 
body or outside of the function body without having to explicitly 
pushing it into a set? Even Haskell and Erlang allow you to define free 
standing variables.

Thanks,
Roger


More information about the nix-dev mailing list