LinuxCommandLibrary

nix3-eval

TLDR

Evaluate Nix expression

$ nix eval --expr '1 + 2'
copy
Evaluate flake attribute
$ nix eval [.#packages.x86_64-linux.default]
copy
Evaluate nixpkgs attribute
$ nix eval nixpkgs#hello.version
copy
Output as JSON
$ nix eval --json nixpkgs#hello.meta
copy
Raw string output
$ nix eval --raw nixpkgs#hello.name
copy
Read from file
$ nix eval -f [file.nix]
copy

SYNOPSIS

nix eval [options] installable

DESCRIPTION

nix eval is the new Nix 3.x command for evaluating Nix expressions. It replaces nix-instantiate --eval with a cleaner interface and flake support.
The command evaluates expressions and prints the result.

PARAMETERS

--expr expr

Evaluate expression.
--json
Output as JSON.
--raw
Raw output (no quotes).
-f file
Evaluate file.
--apply expr
Apply function to result.
--impure
Allow impure evaluation.

EXAMPLES

$ # 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

CAVEATS

Part of experimental Nix 3.x commands. Flakes must be enabled. Different from nix-instantiate syntax.

HISTORY

nix eval was introduced as part of the Nix 2.4 flakes experimental features, redesigning the Nix CLI for better ergonomics.

SEE ALSO

Copied to clipboard