.\" -*- mode: troff; coding: utf-8 -*- .TH "nix-instantiate" "1" "" .SH Name \fCnix-instantiate\fR - instantiate store derivations from Nix expressions .SH Synopsis \fCnix-instantiate\fR [\fC--parse\fR | \fC--eval\fR [\fC--strict\fR] [\fC--json\fR] [\fC--xml\fR] ] [\fC--read-write-mode\fR] [\fC--arg\fR \fIname\fR \fIvalue\fR] [{\fC--attr\fR| \fC-A\fR} \fIattrPath\fR] [\fC--add-root\fR \fIpath\fR] [\fC--expr\fR | \fC-E\fR] \fIfiles…\fR .PP \fCnix-instantiate\fR \fC--find-file\fR \fIfiles…\fR .SH Description The command \fCnix-instantiate\fR generates \fBstore derivations\fR (\fI../glossary.md\fR) from (high-level) Nix expressions. It evaluates the Nix expressions in each of \fIfiles\fR (which defaults to \fI./default.nix\fR). Each top-level expression should evaluate to a derivation, a list of derivations, or a set of derivations. The paths of the resulting store derivations are printed on standard output. .PP If \fIfiles\fR is the character \fC-\fR, then a Nix expression will be read from standard input. .SH Options .IP "\(bu" 2 \fC--add-root\fR \fIpath\fR .br See the \fBcorresponding option\fR (\fInix-store.md\fR) in \fCnix-store\fR. .IP "\(bu" 2 \fC--parse\fR .br Just parse the input files, and print their abstract syntax trees on standard output in ATerm format. .IP "\(bu" 2 \fC--eval\fR .br Just parse and evaluate the input files, and print the resulting values on standard output. No instantiation of store derivations takes place. .IP "\(bu" 2 \fC--find-file\fR .br Look up the given files in Nix’s search path (as specified by the \fCNIX_PATH\fR environment variable). If found, print the corresponding absolute paths on standard output. For instance, if \fCNIX_PATH\fR is \fCnixpkgs=/home/alice/nixpkgs\fR, then \fCnix-instantiate --find-file nixpkgs/default.nix\fR will print \fC/home/alice/nixpkgs/default.nix\fR. .IP "\(bu" 2 \fC--strict\fR .br When used with \fC--eval\fR, recursively evaluate list elements and attributes. Normally, such sub-expressions are left unevaluated (since the Nix expression language is lazy). .RS .IP \fBWarning\fR .IP This option can cause non-termination, because lazy data structures can be infinitely large. .RE .IP "\(bu" 2 \fC--json\fR .br When used with \fC--eval\fR, print the resulting value as an JSON representation of the abstract syntax tree rather than as an ATerm. .IP "\(bu" 2 \fC--xml\fR .br When used with \fC--eval\fR, print the resulting value as an XML representation of the abstract syntax tree rather than as an ATerm. The schema is the same as that used by the \fB\fCtoXML\fR built-in\fR (\fI../expressions/builtins.md\fR). .IP "\(bu" 2 \fC--read-write-mode\fR .br When used with \fC--eval\fR, 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. .SH Examples Instantiating store derivations from a Nix expression, and building them using \fCnix-store\fR: .LP .EX $ nix-instantiate test.nix (instantiate) /nix/store/cigxbmvy6dzix98dxxh9b6shg7ar5bvs-perl-BerkeleyDB-0.26.drv $ nix-store -r $(nix-instantiate test.nix) (build) \&... /nix/store/qhqk4n8ci095g3sdp93x7rgwyh9rdvgk-perl-BerkeleyDB-0.26 (output path) $ ls -l /nix/store/qhqk4n8ci095g3sdp93x7rgwyh9rdvgk-perl-BerkeleyDB-0.26 dr-xr-xr-x 2 eelco users 4096 1970-01-01 01:00 lib \&... .EE .PP You can also give a Nix expression on the command line: .LP .EX $ nix-instantiate -E 'with import { }; hello' /nix/store/j8s4zyv75a724q38cb0r87rlczaiag4y-hello-2.8.drv .EE .PP This is equivalent to: .LP .EX $ nix-instantiate '' -A hello .EE .PP Parsing and evaluating Nix expressions: .LP .EX $ nix-instantiate --parse -E '1 + 2' 1 + 2 .EE .LP .EX $ nix-instantiate --eval -E '1 + 2' 3 .EE .LP .EX $ nix-instantiate --eval --xml -E '1 + 2' .EE .PP The difference between non-strict and strict evaluation: .LP .EX $ nix-instantiate --eval --xml -E 'rec { x = \(dqfoo\(dq; y = x; }' \&... \&... .EE .PP Note that \fCy\fR is left unevaluated (the XML representation doesn’t attempt to show non-normal forms). .LP .EX $ nix-instantiate --eval --xml --strict -E 'rec { x = \(dqfoo\(dq; y = x; }' \&... \&... .EE