Nix (language): Difference between revisions
imported>Ixxie No edit summary |
imported>Makefu No edit summary |
||
Line 10: | Line 10: | ||
== Language Features == | == Language Features == | ||
This section describes the main language features of the nix expression language | |||
=== lazy evaluation === | |||
Not all expressions in nixpkgs will be evaluated and instantiated as nix performs evaluation only when needed for a finished output. In the following example <code>abort</code> will never be triggered as the variable it belogs to is unused: | |||
<syntaxHighlight lang=nix> | |||
let | |||
a = abort "will never happen"; | |||
b = "hello"; | |||
c = "world" | |||
in b + c | |||
</syntaxHighlight> | |||
=== | === functional paradigm === | ||
Functional Programming is a style of building the structure and elements of computer programs—that treats computation as the evaluation of mathematical functions and avoids changing-state and mutable data. It is a declarative programming paradigm, which means programming is done with expressions or declarations instead of statements. | |||
see also: [https://en.wikipedia.org/wiki/Functional_programming] | |||
=== purity === | |||
A pure function is a function where the return value is only determined by its input values, without observable side effects. In Nix, all build operations try to be as pure as possible to achieve reproducible builds. This means that wherever you build the packages as few side effects as possible should have an impact onto the build. | |||
=== expressions === | |||
When Nix tutorials talk about '''Nix Expressions''' they typically mean the definition of a function with multiple inputs which as a result in a derivation. However a Nix expression can be everything, from a simple string, to function to a set of expressions. | |||
=== | === types === | ||
TODO | TODO | ||
=== | === functions === | ||
TODO | TODO | ||
=== | === imports === | ||
TODO | TODO | ||
=== | === notable constructs === | ||
Nix looks a lot like JSON with functions but also provides a number of very specialized constructs which can help you build clean and easy to read expressions. In this sub-chapter the most notable constructs will be shown by example: | Nix looks a lot like JSON with functions but also provides a number of very specialized constructs which can help you build clean and easy to read expressions. In this sub-chapter the most notable constructs will be shown by example: | ||