nix-instantiate1Nixnix-instantiateinstantiate store derivations from Nix expressionsnix-instantiatenamevalueattrPathpathfilesDescriptionThe command nix-instantiate generates store derivations from (high-level)
Nix expressions. It loads and evaluates the Nix expressions in each
of files. 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.If files is the character
-, then a Nix expression will be read from standard
input.Most users and developers don’t need to use this command
(nix-env and nix-build perform
store derivation instantiation from Nix expressions automatically).
It is most commonly used for implementing new deployment
policies.See also for a list of common options.OptionspathSee the corresponding
options in nix-store.Just parse the input files, and print their
abstract syntax trees on standard output in ATerm
format.Just parse and evaluate the input files, and print
the resulting values on standard output. No instantiation of
store derivations takes place.When used with and
, print the resulting expression as an
XML representation of the abstract syntax tree rather than as an
ATerm. The schema is the same as that used by the toXML
built-in.When used with ,
recursively evaluate list elements and attributes. Normally, such
sub-expressions are left unevaluated (since the Nix expression
language is lazy).This option can cause non-termination, because lazy
data structures can be infinitely large.ExamplesInstantiating store derivations from a Nix expression, and
building them using nix-store:
$ 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
...Parsing and evaluating Nix expressions:
$ echo '"foo" + "bar"' | nix-instantiate --parse-only -
OpPlus(Str("foo"),Str("bar"))
$ echo '"foo" + "bar"' | nix-instantiate --eval-only -
Str("foobar")
$ echo '"foo" + "bar"' | nix-instantiate --eval-only --xml -
]]>The difference between non-strict and strict evaluation:
$ echo 'rec { x = "foo"; y = x; }' | nix-instantiate --eval-only --xml -
...]]>
...
Note that y is left unevaluated (the XML
representation doesn’t attempt to show non-normal forms).
$ echo 'rec { x = "foo"; y = x; }' | nix-instantiate --eval-only --xml --strict -
...]]>
...