nix-build 1 Nix nix-build build a Nix expression nix-build name value name value attrPath drvlink outlink cmd regexp paths Description The nix-build command builds the derivations described by the Nix expressions in paths. If the build succeeds, it places a symlink to the result in the current directory. The symlink is called result. If there are multiple Nix expressions, or the Nix expressions evaluate to multiple derivations, multiple sequentially numbered symlinks are created (result, result-2, and so on). If no paths are specified, then nix-build will use default.nix in the current directory, if it exists. nix-build is essentially a wrapper around nix-instantiate (to translate a high-level Nix expression to a low-level store derivation) and nix-store --realise (to build the store derivation). The result of the build is automatically registered as a root of the Nix garbage collector. This root disappears automatically when the result symlink is deleted or renamed. So don’t rename the symlink. The subcommand nix-build --run-env will build the dependencies of the derivation, but not the derivation itself. It will then start an interactive shell in which all environment variables defined by the derivation have been set to their corresponding values, and the script $stdenv/setup has been sourced. This is useful for reproducing the environment of a derivation for development. Options All options not listed here are passed to nix-store --realise, except for and / which are passed to nix-instantiate. See also . drvlink Add a symlink named drvlink to the store derivation produced by nix-instantiate. The derivation is a root of the garbage collector until the symlink is deleted or renamed. If there are multiple derivations, numbers are suffixed to drvlink to distinguish between them. Shorthand for ./derivation. Do not create a symlink to the output path. Note that as a result the output does not become a root of the garbage collector, and so might be deleted by nix-store --gc. / outlink Change the name of the symlink to the output path created from result to outlink. The following options apply to nix-build --run-env. cmd In the environment of the derivation, run the shell command cmd instead of starting an interactive shell. However, if you end the shell command with return, you still get an interactive shell. This can be useful for doing any additional initialisation. regexp Do not build any dependencies whose store path matches the regular expression regexp. This option may be specified multiple times. If this flag is specified, the environment is almost entirely cleared before the interactive shell is started, so you get an environment that more closely corresponds to the “real” Nix build. A few variables, in particular HOME, USER and DISPLAY, are retained. Note that ~/.bashrc and (depending on your Bash installation) /etc/bashrc are still sourced, so any variables set there will affect the interactive shell. Examples $ nix-build '<nixpkgs>' -A firefox store derivation is /nix/store/qybprl8sz2lc...-firefox-1.5.0.7.drv /nix/store/d18hyl92g30l...-firefox-1.5.0.7 $ ls -l result lrwxrwxrwx ... result -> /nix/store/d18hyl92g30l...-firefox-1.5.0.7 $ ls ./result/bin/ firefox firefox-config To build the dependencies of the package Pan, and start an interactive shell in which to build it: $ nix-build '<nixpkgs>' --run-env -A pan $ unpackPhase $ cd pan-* $ configurePhase $ buildPhase $ ./pan/gui/pan To clear the environment first, and do some additional automatic initialisation of the interactive shell: $ nix-build '<nixpkgs>' --run-env -A pan --pure \ --command 'export NIX_DEBUG=1; export NIX_CORES=8; return' If a derivation has multiple outputs, nix-build will build the default (first) output. You can also build all outputs: $ nix-build '<nixpkgs>' -A openssl.all This will create a symlink for each output named result-outputname. The suffix is omitted if the output name is out. So if openssl has outputs out, bin and man, nix-build will create symlinks result, result-bin and result-man. It’s also possible to build a specific output: $ nix-build '<nixpkgs>' -A openssl.man This will create a symlink result-man. Environment variables