blob: eb9f753c52ff1a380a1c3536fc356631b80194e5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
R""(
**Note:** this command's interface is based heavily around [*installables*](./nix.md#installables), which you may want to read about first (`nix --help`).
# Examples
* Evaluate a Nix expression given on the command line:
```console
# nix eval --expr '1 + 2'
```
* Evaluate a Nix expression to JSON using the short-form expression flag:
```console
# nix eval --json -E '{ x = 1; }'
{"x":1}
```
* Evaluate a Nix expression from a file:
```console
# nix eval --file ./my-nixpkgs hello.name
```
* Get the current version of the `nixpkgs` flake:
```console
# nix eval --raw nixpkgs#lib.version
```
* Print the store path of the Hello package:
```console
# nix eval --raw nixpkgs#hello
```
* Get a list of checks in the `nix` flake:
```console
# nix eval nix#checks.x86_64-linux --apply builtins.attrNames
```
* Generate a directory with the specified contents:
```console
# nix eval --write-to ./out --expr '{ foo = "bar"; subdir.bla = "123"; }'
# cat ./out/foo
bar
# cat ./out/subdir/bla
123
# Description
This command evaluates the given Nix expression and prints the
result on standard output.
# Output format
`nix eval` can produce output in several formats:
* By default, the evaluation result is printed as a Nix expression.
* With `--json`, the evaluation result is printed in JSON format. Note
that this fails if the result contains values that are not
representable as JSON, such as functions.
* With `--raw`, the evaluation result must be a string, which is
printed verbatim, without any quoting.
* With `--write-to` *path*, the evaluation result must be a string or
a nested attribute set whose leaf values are strings. These strings
are written to files named *path*/*attrpath*. *path* must not
already exist.
)""
|