LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

nix3-eval

man page for nix eval, the Nix expression evaluator

TLDR

Evaluate Nix expression
$ nix eval --expr '1 + 2'
copy
Evaluate flake attribute
$ nix eval [.#packages.x86_64-linux.default.name]
copy
Evaluate nixpkgs attribute
$ nix eval nixpkgs#hello.version
copy
Output as JSON
$ nix eval --json nixpkgs#hello.meta.license
copy
Raw string output
$ nix eval --raw nixpkgs#hello.name
copy
Read from file
$ nix eval -f [file.nix]
copy
Apply a function to the result
$ nix eval nixpkgs#lib --apply 'lib: lib.version'
copy
Write an attribute set of strings as files
$ nix eval --write-to [./out] --expr '{ foo = "bar"; }'
copy

SYNOPSIS

nix eval [options] [installable]

DESCRIPTION

nix3-eval is the manual page for nix eval, the new-CLI command for evaluating Nix expressions. It replaces nix-instantiate --eval with a cleaner interface and flake support.

$ # Simple expression
nix eval --expr 'builtins.length [1 2 3]'
# Output: 3

# Flake attribute
nix eval .#packages.x86_64-linux.hello.version

# With function application
nix eval nixpkgs#lib --apply 'lib: lib.version'
copy

PARAMETERS

--expr expr

Interpret installables as attribute paths relative to this expression.
-f, --file file
Interpret installables as attribute paths relative to the expression in file. Implies --impure.
--json
Output as JSON.
--raw
Raw output (no quotes). The result must be a string.
--apply expr
Apply function to result.
--write-to path
Write a string or attribute set of strings to files under path.
--read-only
Do not instantiate derivations during evaluation.
--impure
Allow impure evaluation.

INSTALL

sudo apt install nix-bin
copy
sudo dnf install nix
copy
sudo pacman -S nix
copy
sudo apk add nix
copy
sudo zypper install nix
copy
nix profile install nixpkgs#nix
copy

CAVEATS

There is no nix3 executable: the new-CLI man pages are named nix3-subcommand to avoid clashing with the old nix-* tools. Use man nix3-eval or nix eval --help.Part of the experimental new Nix CLI: the nix-command feature (and flakes for flake references) must be enabled. Different from nix-instantiate syntax.

HISTORY

nix eval first shipped with the new nix command in Nix 2.0 (2018) and was redesigned around flakes and installables in Nix 2.4 (2021).

SEE ALSO

RESOURCES

Copied to clipboard
Kai