3 ms·
Everything in Nix evaluates to a single value, including 'let' and even complete files. There are no blocks like in an imperative language. The '{}' in Nix are
by grumbel 4y ago
Everything in Nix evaluates to a single value, including 'let' and even complete files. There are no blocks like in an imperative language. The '{}' in Nix are not blocks, but sets, known in other languages as maps or dicts. Thus what comes after the 'in' in a 'let' is an expression itself and has to return a single value.
Meaning whenever you see a 'let', look at the surrounding, it will probably look like '{ a = (let x = 5; in x); }' which is just a convoluted way to write '{ a = 5; }'. Or often you'll see 'a = (foo: let ...)' in this case the ':' declares a function taking the argument 'foo'.
You can play around with the language in the 'nix repl'. The language itself is really simple, but not very obvious when just looking at a code snippet it.
And yes, there is an argument to be made that a purely expression based language is not very ergonomic, but it keeps the Nix language simple.