* Document --arg.
This commit is contained in:
parent
6f2bfd92b6
commit
5d769de8a3
6 changed files with 53 additions and 15 deletions
|
|
@ -217,6 +217,46 @@
|
|||
</varlistentry>
|
||||
|
||||
|
||||
<varlistentry><term><option>--arg</option> <replaceable>name</replaceable> <replaceable>value</replaceable></term>
|
||||
|
||||
<listitem><para>This option is accepted by
|
||||
<command>nix-env</command>, <command>nix-instantiate</command> and
|
||||
<command>nix-build</command>. When evaluating Nix expressions, the
|
||||
expression evaluator will automatically try to call functions that
|
||||
it encounters. It can automatically call functions for which every
|
||||
argument has a default value (e.g.,
|
||||
<literal>{<replaceable>argName</replaceable> ?
|
||||
<replaceable>defaultValue</replaceable>}:
|
||||
<replaceable>...</replaceable></literal>). With
|
||||
<option>--arg</option>, you can also call functions that have
|
||||
arguments without a default value (or override a default value).
|
||||
That is, if the evaluator encounters a function with an argument
|
||||
named <replaceable>name</replaceable>, it will call it with value
|
||||
<replaceable>value</replaceable>.</para>
|
||||
|
||||
<para>For instance, the file
|
||||
<literal>pkgs/top-level/all-packages.nix</literal> in Nixpkgs is
|
||||
actually a function:
|
||||
|
||||
<programlisting>
|
||||
{ # The system (e.g., `i686-linux') for which to build the packages.
|
||||
system ? __currentSystem
|
||||
<replaceable>...</replaceable>
|
||||
}: <replaceable>...</replaceable></programlisting>
|
||||
|
||||
So if you call this Nix expression (e.g., when you do
|
||||
<literal>nix-env -i <replaceable>pkgname</replaceable></literal>),
|
||||
the function will be called automatically using the value <link
|
||||
linkend='builtin-currentSystem'><literal>__currentSystem</literal></link>
|
||||
for the <literal>system</literal> argument. You can override this
|
||||
using <option>--arg</option>, e.g., <literal>nix-env -i
|
||||
<replaceable>pkgname</replaceable> --arg system
|
||||
\"i686-freebsd\"</literal>. (Note that since the argument is a Nix
|
||||
string literal, you have to escape the quotes.)</para></listitem>
|
||||
|
||||
</varlistentry>
|
||||
|
||||
|
||||
</variablelist>
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue