Nix (language): Difference between revisions

imported>Makefu
imported>Makefu
add rec
Line 53: Line 53:
The <code>with</code> statement introduces the lexical scope of a set into the expression which follows.
The <code>with</code> statement introduces the lexical scope of a set into the expression which follows.
Common usages are:
Common usages are:
===== '''On top of expressions''' =====
'''On top of expressions''':
 
You will see the with statement a lot at the beginning of expression definition. Most of the time it is used to load the lib functions into the namespace for quick access.
You will see the with statement a lot at the beginning of expression definition. Most of the time it is used to load the lib functions into the namespace for quick access.
<syntaxHighlight lang=nix>
<syntaxHighlight lang=nix>
Line 83: Line 84:
</syntaxHighlight>
</syntaxHighlight>


===== '''In package input definitions''' =====
'''In package input definitions''':
<syntaxHighlight lang=nix>
<syntaxHighlight lang=nix>
{pkgs}:
{pkgs}:
Line 99: Line 100:
}
}
</syntaxHighlight>
</syntaxHighlight>
===== '''In the package meta tag''' =====
 
'''In the package meta tag''':
<syntaxHighlight lang=nix>
<syntaxHighlight lang=nix>
{stdenv, ...}:
{stdenv, ...}:
Line 164: Line 166:


==== <code>rec</code> statement ====
==== <code>rec</code> statement ====
TODO
The <code>rec</code> expression turns a basic set into a set where self-referencing is possible. This can be used when the <code>let</code> expression would create too much clutter. It is often seen in package derivation descriptions.


Sample usage:
<syntaxHighlight lang=nix>
rec {
  x = y - 100;
  y = 123;
}.x
=> 23
</syntaxHighlight>
== Learning Resources ==
== Learning Resources ==