.\" -*- mode: troff; coding: utf-8 -*- .TH "nix3-eval" "1" "" .PP \fBWarning\fR: This program is \fBexperimental\fR and its interface is subject to change. .SH Name \fCnix eval\fR - evaluate a Nix expression .SH Synopsis \fCnix eval\fR [\fIoption\fR\[u2026]] \fIinstallable\fR .SH Examples .IP "\(bu" 2 Evaluate a Nix expression given on the command line: .LP .EX # nix eval --expr '1 + 2' .EE .IP "\(bu" 2 Evaluate a Nix expression to JSON: .LP .EX # nix eval --json --expr '{ x = 1; }' {\(dqx\(dq:1} .EE .IP "\(bu" 2 Evaluate a Nix expression from a file: .LP .EX # nix eval -f ./my-nixpkgs hello.name .EE .IP "\(bu" 2 Get the current version of the \fCnixpkgs\fR flake: .LP .EX # nix eval --raw nixpkgs#lib.version .EE .IP "\(bu" 2 Print the store path of the Hello package: .LP .EX # nix eval --raw nixpkgs#hello .EE .IP "\(bu" 2 Get a list of checks in the \fCnix\fR flake: .LP .EX # nix eval nix#checks.x86_64-linux --apply builtins.attrNames .EE .IP "\(bu" 2 Generate a directory with the specified contents: .LP .EX # nix eval --write-to ./out --expr '{ foo = \(dqbar\(dq; subdir.bla = \(dq123\(dq; }' # cat ./out/foo bar # cat ./out/subdir/bla 123 .EE .SH Description This command evaluates the Nix expression \fIinstallable\fR and prints the result on standard output. .SH Output format \fCnix eval\fR can produce output in several formats: .IP "\(bu" 2 By default, the evaluation result is printed as a Nix expression. .IP "\(bu" 2 With \fC--json\fR, 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. .IP "\(bu" 2 With \fC--raw\fR, the evaluation result must be a string, which is printed verbatim, without any quoting. .IP "\(bu" 2 With \fC--write-to\fR \fIpath\fR, the evaluation result must be a string or a nested attribute set whose leaf values are strings. These strings are written to files named \fIpath\fR/\fIattrpath\fR. \fIpath\fR must not already exist. .SH Options .IP "\(bu" 2 \fC--apply\fR \fIexpr\fR .br Apply the function \fIexpr\fR to each argument. .IP "\(bu" 2 \fC--json\fR .br Produce output in JSON format, suitable for consumption by another program. .IP "\(bu" 2 \fC--raw\fR .br Print strings without quotes or escaping. .IP "\(bu" 2 \fC--read-only\fR .br Do not instantiate each evaluated derivation. This improves performance, but can cause errors when accessing store paths of derivations during evaluation. .IP "\(bu" 2 \fC--write-to\fR \fIpath\fR .br Write a string or attrset of strings to \fIpath\fR. .LP \fBCommon evaluation options:\fR .IP "\(bu" 2 \fC--arg\fR \fIname\fR \fIexpr\fR .br Pass the value \fIexpr\fR as the argument \fIname\fR to Nix functions. .IP "\(bu" 2 \fC--argstr\fR \fIname\fR \fIstring\fR .br Pass the string \fIstring\fR as the argument \fIname\fR to Nix functions. .IP "\(bu" 2 \fC--eval-store\fR \fIstore-url\fR .br The Nix store to use for evaluations. .IP "\(bu" 2 \fC--impure\fR .br Allow access to mutable paths and repositories. .IP "\(bu" 2 \fC--include\fR / \fC-I\fR \fIpath\fR .br Add \fIpath\fR to the list of locations used to look up \fC<...>\fR file names. .IP "\(bu" 2 \fC--override-flake\fR \fIoriginal-ref\fR \fIresolved-ref\fR .br Override the flake registries, redirecting \fIoriginal-ref\fR to \fIresolved-ref\fR. .LP \fBCommon flake-related options:\fR .IP "\(bu" 2 \fC--commit-lock-file\fR .br Commit changes to the flake\[u2019]s lock file. .IP "\(bu" 2 \fC--inputs-from\fR \fIflake-url\fR .br Use the inputs of the specified flake as registry entries. .IP "\(bu" 2 \fC--no-registries\fR .br Don\[u2019]t allow lookups in the flake registries. This option is deprecated; use \fC--no-use-registries\fR. .IP "\(bu" 2 \fC--no-update-lock-file\fR .br Do not allow any updates to the flake\[u2019]s lock file. .IP "\(bu" 2 \fC--no-write-lock-file\fR .br Do not write the flake\[u2019]s newly generated lock file. .IP "\(bu" 2 \fC--override-input\fR \fIinput-path\fR \fIflake-url\fR .br Override a specific flake input (e.g. \fCdwarffs/nixpkgs\fR). This implies \fC--no-write-lock-file\fR. .IP "\(bu" 2 \fC--recreate-lock-file\fR .br Recreate the flake\[u2019]s lock file from scratch. .IP "\(bu" 2 \fC--update-input\fR \fIinput-path\fR .br Update a specific flake input (ignoring its previous entry in the lock file). .LP \fBOptions that change the interpretation of installables:\fR .IP "\(bu" 2 \fC--derivation\fR .br Operate on the store derivation rather than its outputs. .IP "\(bu" 2 \fC--expr\fR \fIexpr\fR .br Interpret installables as attribute paths relative to the Nix expression \fIexpr\fR. .IP "\(bu" 2 \fC--file\fR / \fC-f\fR \fIfile\fR .br Interpret installables as attribute paths relative to the Nix expression stored in \fIfile\fR. If \fIfile\fR is the character -, then a Nix expression will be read from standard input.