Home Explore Blog CI



nix

3rd chunk of `doc/manual/source/command-ref/opt-common.md`
0f3bd2e27bf7af7eccb0de2325ad8518f942c7a17aeca6470000000100000a00
  When this option is used, no attempt is made to open the Nix database.
  Most Nix operations do need database access, so those operations will fail.

- <span id="opt-arg">[`--arg`](#opt-arg)</span> *name* *value*

  This option is accepted by `nix-env`, `nix-instantiate`, `nix-shell` and `nix-build`.
  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](@docroot@/language/syntax.md#functions) (e.g., `{ argName ?  defaultValue }: ...`).

  With `--arg`, 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 *name*, it will call it with value *value*.

  For instance, the top-level `default.nix` in Nixpkgs is actually a function:

  ```nix
  { # The system (e.g., `i686-linux') for which to build the packages.
    system ? builtins.currentSystem
    ...
  }: ...
  ```

  So if you call this Nix expression (e.g., when you do `nix-env --install --attr pkgname`), the function will be called automatically using the value [`builtins.currentSystem`](@docroot@/language/builtins.md) for the `system` argument.
  You can override this using `--arg`, e.g., `nix-env --install --attr pkgname --arg system \"i686-freebsd\"`.
  (Note that since the argument is a Nix string literal, you have to escape the quotes.)

- <span id="opt-arg-from-file">[`--arg-from-file`](#opt-arg-from-file)</span> *name* *path*

  Pass the contents of file *path* as the argument *name* to Nix functions.

- <span id="opt-arg-from-stdin">[`--arg-from-stdin`](#opt-arg-from-stdin)</span> *name*

  Pass the contents of stdin as the argument *name* to Nix functions.

- <span id="opt-argstr">[`--argstr`](#opt-argstr)</span> *name* *value*

  This option is like `--arg`, only the value is not a Nix expression but a string.
  So instead of `--arg system \"i686-linux\"` (the outer quotes are to keep the shell happy) you can say `--argstr system i686-linux`.

- <span id="opt-attr">[`--attr`](#opt-attr)</span> / `-A` *attrPath*

  Select an attribute from the top-level Nix expression being evaluated.
  (`nix-env`, `nix-instantiate`, `nix-build` and `nix-shell` only.)
  The *attribute path* *attrPath* is a sequence of attribute names separated by dots.
  For instance, given a top-level Nix expression *e*, the attribute path `xorg.xorgserver` would cause the expression `e.xorg.xorgserver` to be used.

Title: Nix Command Options: Passing Arguments and Selecting Attributes
Summary
This section details options for passing arguments to Nix functions during evaluation, including `--arg` for arbitrary expressions, `--arg-from-file` and `--arg-from-stdin` for reading arguments from files or standard input, and `--argstr` for passing string literals. It also covers the `--attr` option for selecting specific attributes from a top-level Nix expression.