2020-07-24 13:56:19 +03:00
|
|
|
|
# Name
|
2020-07-23 13:58:42 +03:00
|
|
|
|
|
2020-07-24 13:56:19 +03:00
|
|
|
|
`nix-instantiate` - instantiate store derivations from Nix expressions
|
2020-07-23 13:58:42 +03:00
|
|
|
|
|
2020-07-24 13:56:19 +03:00
|
|
|
|
# Synopsis
|
2020-07-23 13:58:42 +03:00
|
|
|
|
|
2020-07-24 13:56:19 +03:00
|
|
|
|
`nix-instantiate`
|
|
|
|
|
[`--parse` | `--eval` [`--strict`] [`--json`] [`--xml`] ]
|
|
|
|
|
[`--read-write-mode`]
|
|
|
|
|
[`--arg` *name* *value*]
|
|
|
|
|
[{`--attr`| `-A`} *attrPath*]
|
|
|
|
|
[`--add-root` *path*]
|
|
|
|
|
[`--expr` | `-E`]
|
|
|
|
|
*files…*
|
2020-07-23 13:58:42 +03:00
|
|
|
|
|
2020-07-24 13:56:19 +03:00
|
|
|
|
`nix-instantiate` `--find-file` *files…*
|
2020-07-23 13:58:42 +03:00
|
|
|
|
|
|
|
|
|
# Description
|
|
|
|
|
|
2022-12-20 16:37:40 +02:00
|
|
|
|
The command `nix-instantiate` produces [store derivation]s from (high-level) Nix expressions.
|
|
|
|
|
It evaluates the Nix expressions in each of *files* (which defaults to
|
2020-07-23 15:28:05 +03:00
|
|
|
|
*./default.nix*). Each top-level expression should evaluate to a
|
2020-07-24 16:46:16 +03:00
|
|
|
|
derivation, a list of derivations, or a set of derivations. The paths
|
|
|
|
|
of the resulting store derivations are printed on standard output.
|
2020-07-23 13:58:42 +03:00
|
|
|
|
|
2024-04-12 18:06:47 +03:00
|
|
|
|
[store derivation]: @docroot@/glossary.md#gloss-store-derivation
|
2022-12-20 16:37:40 +02:00
|
|
|
|
|
2020-07-23 15:28:05 +03:00
|
|
|
|
If *files* is the character `-`, then a Nix expression will be read from
|
2020-07-23 13:58:42 +03:00
|
|
|
|
standard input.
|
|
|
|
|
|
|
|
|
|
# Options
|
|
|
|
|
|
2024-06-17 18:49:09 +03:00
|
|
|
|
- `--add-root` *path*
|
|
|
|
|
|
2020-09-03 12:22:00 +03:00
|
|
|
|
See the [corresponding option](nix-store.md) in `nix-store`.
|
2020-07-23 13:58:42 +03:00
|
|
|
|
|
2024-06-17 18:49:09 +03:00
|
|
|
|
- `--parse`
|
|
|
|
|
|
2020-07-23 13:58:42 +03:00
|
|
|
|
Just parse the input files, and print their abstract syntax trees on
|
2024-01-09 21:13:45 +02:00
|
|
|
|
standard output as a Nix expression.
|
2020-07-23 13:58:42 +03:00
|
|
|
|
|
2024-06-17 18:49:09 +03:00
|
|
|
|
- `--eval`
|
|
|
|
|
|
2020-07-23 13:58:42 +03:00
|
|
|
|
Just parse and evaluate the input files, and print the resulting
|
|
|
|
|
values on standard output. No instantiation of store derivations
|
|
|
|
|
takes place.
|
|
|
|
|
|
2024-01-09 21:13:45 +02:00
|
|
|
|
> **Warning**
|
|
|
|
|
>
|
2024-01-12 21:31:49 +02:00
|
|
|
|
> This option produces output which can be parsed as a Nix expression which
|
|
|
|
|
> will produce a different result than the input expression when evaluated.
|
|
|
|
|
> For example, these two Nix expressions print the same result despite
|
|
|
|
|
> having different meaning:
|
2024-01-09 21:13:45 +02:00
|
|
|
|
>
|
|
|
|
|
> ```console
|
|
|
|
|
> $ nix-instantiate --eval --expr '{ a = {}; }'
|
|
|
|
|
> { a = <CODE>; }
|
|
|
|
|
> $ nix-instantiate --eval --expr '{ a = <CODE>; }'
|
|
|
|
|
> { a = <CODE>; }
|
|
|
|
|
> ```
|
|
|
|
|
>
|
|
|
|
|
> For human-readable output, `nix eval` (experimental) is more informative:
|
|
|
|
|
>
|
|
|
|
|
> ```console
|
|
|
|
|
> $ nix-instantiate --eval --expr 'a: a'
|
|
|
|
|
> <LAMBDA>
|
|
|
|
|
> $ nix eval --expr 'a: a'
|
|
|
|
|
> «lambda @ «string»:1:1»
|
|
|
|
|
> ```
|
|
|
|
|
>
|
|
|
|
|
> For machine-readable output, the `--xml` option produces unambiguous
|
|
|
|
|
> output:
|
|
|
|
|
>
|
|
|
|
|
> ```console
|
|
|
|
|
> $ nix-instantiate --eval --xml --expr '{ foo = <CODE>; }'
|
|
|
|
|
> <?xml version='1.0' encoding='utf-8'?>
|
|
|
|
|
> <expr>
|
|
|
|
|
> <attrs>
|
|
|
|
|
> <attr column="3" line="1" name="foo">
|
|
|
|
|
> <unevaluated />
|
|
|
|
|
> </attr>
|
|
|
|
|
> </attrs>
|
|
|
|
|
> </expr>
|
|
|
|
|
> ```
|
|
|
|
|
|
2024-06-17 18:49:09 +03:00
|
|
|
|
- `--find-file`
|
|
|
|
|
|
2020-07-23 13:58:42 +03:00
|
|
|
|
Look up the given files in Nix’s search path (as specified by the
|
2020-07-24 12:43:44 +03:00
|
|
|
|
`NIX_PATH` environment variable). If found, print the corresponding
|
|
|
|
|
absolute paths on standard output. For instance, if `NIX_PATH` is
|
|
|
|
|
`nixpkgs=/home/alice/nixpkgs`, then `nix-instantiate --find-file
|
|
|
|
|
nixpkgs/default.nix` will print `/home/alice/nixpkgs/default.nix`.
|
2020-07-23 13:58:42 +03:00
|
|
|
|
|
2024-06-17 18:49:09 +03:00
|
|
|
|
- `--strict`
|
|
|
|
|
|
2020-07-23 13:58:42 +03:00
|
|
|
|
When used with `--eval`, recursively evaluate list elements and
|
|
|
|
|
attributes. Normally, such sub-expressions are left unevaluated
|
2022-08-04 12:36:32 +03:00
|
|
|
|
(since the Nix language is lazy).
|
2020-07-24 13:56:19 +03:00
|
|
|
|
|
2020-07-23 13:58:42 +03:00
|
|
|
|
> **Warning**
|
2020-07-24 13:56:19 +03:00
|
|
|
|
>
|
2020-07-23 13:58:42 +03:00
|
|
|
|
> This option can cause non-termination, because lazy data
|
|
|
|
|
> structures can be infinitely large.
|
|
|
|
|
|
2024-06-17 18:49:09 +03:00
|
|
|
|
- `--json`
|
|
|
|
|
|
2020-07-23 13:58:42 +03:00
|
|
|
|
When used with `--eval`, print the resulting value as an JSON
|
2024-01-09 21:13:45 +02:00
|
|
|
|
representation of the abstract syntax tree rather than as a Nix expression.
|
2020-07-23 13:58:42 +03:00
|
|
|
|
|
2024-06-17 18:49:09 +03:00
|
|
|
|
- `--xml`
|
|
|
|
|
|
2020-07-23 13:58:42 +03:00
|
|
|
|
When used with `--eval`, print the resulting value as an XML
|
2024-01-09 21:13:45 +02:00
|
|
|
|
representation of the abstract syntax tree rather than as a Nix expression.
|
2020-07-23 13:58:42 +03:00
|
|
|
|
The schema is the same as that used by the [`toXML`
|
2022-08-04 12:36:32 +03:00
|
|
|
|
built-in](../language/builtins.md).
|
2020-07-23 13:58:42 +03:00
|
|
|
|
|
2024-06-17 18:49:09 +03:00
|
|
|
|
- `--read-write-mode`
|
|
|
|
|
|
2020-07-23 13:58:42 +03:00
|
|
|
|
When used with `--eval`, perform evaluation in read/write mode so
|
|
|
|
|
nix language features that require it will still work (at the cost
|
|
|
|
|
of needing to do instantiation of every evaluated derivation). If
|
|
|
|
|
this option is not enabled, there may be uninstantiated store paths
|
|
|
|
|
in the final output.
|
|
|
|
|
|
2023-03-23 17:27:41 +02:00
|
|
|
|
{{#include ./opt-common.md}}
|
|
|
|
|
|
|
|
|
|
{{#include ./env-common.md}}
|
2020-07-23 13:58:42 +03:00
|
|
|
|
|
|
|
|
|
# Examples
|
|
|
|
|
|
2022-12-20 16:37:40 +02:00
|
|
|
|
Instantiate [store derivation]s from a Nix expression, and build them using `nix-store`:
|
2020-07-23 13:58:42 +03:00
|
|
|
|
|
2020-07-31 16:43:25 +03:00
|
|
|
|
```console
|
|
|
|
|
$ nix-instantiate test.nix (instantiate)
|
|
|
|
|
/nix/store/cigxbmvy6dzix98dxxh9b6shg7ar5bvs-perl-BerkeleyDB-0.26.drv
|
2020-07-24 13:56:19 +03:00
|
|
|
|
|
2023-04-30 16:52:38 +03:00
|
|
|
|
$ nix-store --realise $(nix-instantiate test.nix) (build)
|
2020-07-31 16:43:25 +03:00
|
|
|
|
...
|
|
|
|
|
/nix/store/qhqk4n8ci095g3sdp93x7rgwyh9rdvgk-perl-BerkeleyDB-0.26 (output path)
|
2020-07-24 13:56:19 +03:00
|
|
|
|
|
2020-07-31 16:43:25 +03:00
|
|
|
|
$ ls -l /nix/store/qhqk4n8ci095g3sdp93x7rgwyh9rdvgk-perl-BerkeleyDB-0.26
|
|
|
|
|
dr-xr-xr-x 2 eelco users 4096 1970-01-01 01:00 lib
|
|
|
|
|
...
|
|
|
|
|
```
|
2020-07-23 13:58:42 +03:00
|
|
|
|
|
|
|
|
|
You can also give a Nix expression on the command line:
|
|
|
|
|
|
2020-07-31 16:43:25 +03:00
|
|
|
|
```console
|
2023-04-30 16:52:38 +03:00
|
|
|
|
$ nix-instantiate --expr 'with import <nixpkgs> { }; hello'
|
2020-07-31 16:43:25 +03:00
|
|
|
|
/nix/store/j8s4zyv75a724q38cb0r87rlczaiag4y-hello-2.8.drv
|
|
|
|
|
```
|
2020-07-23 13:58:42 +03:00
|
|
|
|
|
|
|
|
|
This is equivalent to:
|
|
|
|
|
|
2020-07-31 16:43:25 +03:00
|
|
|
|
```console
|
2023-04-30 16:52:38 +03:00
|
|
|
|
$ nix-instantiate '<nixpkgs>' --attr hello
|
2020-07-31 16:43:25 +03:00
|
|
|
|
```
|
2020-07-23 13:58:42 +03:00
|
|
|
|
|
|
|
|
|
Parsing and evaluating Nix expressions:
|
|
|
|
|
|
2020-07-31 16:43:25 +03:00
|
|
|
|
```console
|
2023-04-30 16:52:38 +03:00
|
|
|
|
$ nix-instantiate --parse --expr '1 + 2'
|
2020-07-31 16:43:25 +03:00
|
|
|
|
1 + 2
|
|
|
|
|
```
|
2020-07-24 13:56:19 +03:00
|
|
|
|
|
2020-07-31 16:43:25 +03:00
|
|
|
|
```console
|
2023-04-30 16:52:38 +03:00
|
|
|
|
$ nix-instantiate --eval --expr '1 + 2'
|
2020-07-31 16:43:25 +03:00
|
|
|
|
3
|
|
|
|
|
```
|
2020-07-24 13:56:19 +03:00
|
|
|
|
|
2020-07-31 16:43:25 +03:00
|
|
|
|
```console
|
2023-04-30 16:52:38 +03:00
|
|
|
|
$ nix-instantiate --eval --xml --expr '1 + 2'
|
2020-07-31 16:43:25 +03:00
|
|
|
|
<?xml version='1.0' encoding='utf-8'?>
|
|
|
|
|
<expr>
|
|
|
|
|
<int value="3" />
|
|
|
|
|
</expr>
|
|
|
|
|
```
|
2020-07-23 13:58:42 +03:00
|
|
|
|
|
|
|
|
|
The difference between non-strict and strict evaluation:
|
|
|
|
|
|
2020-07-31 16:43:25 +03:00
|
|
|
|
```console
|
2024-01-09 21:13:45 +02:00
|
|
|
|
$ nix-instantiate --eval --xml --expr '{ x = {}; }'
|
|
|
|
|
<?xml version='1.0' encoding='utf-8'?>
|
|
|
|
|
<expr>
|
|
|
|
|
<attrs>
|
|
|
|
|
<attr column="3" line="1" name="x">
|
|
|
|
|
<unevaluated />
|
|
|
|
|
</attr>
|
|
|
|
|
</attrs>
|
|
|
|
|
</expr>
|
2020-07-23 13:58:42 +03:00
|
|
|
|
|
2024-01-09 21:13:45 +02:00
|
|
|
|
$ nix-instantiate --eval --xml --strict --expr '{ x = {}; }'
|
|
|
|
|
<?xml version='1.0' encoding='utf-8'?>
|
|
|
|
|
<expr>
|
|
|
|
|
<attrs>
|
|
|
|
|
<attr column="3" line="1" name="x">
|
|
|
|
|
<attrs>
|
|
|
|
|
</attrs>
|
|
|
|
|
</attr>
|
|
|
|
|
</attrs>
|
|
|
|
|
</expr>
|
2020-07-31 16:43:25 +03:00
|
|
|
|
```
|