.\" -*- mode: troff; coding: utf-8 -*- .TH "nix-build" "1" "" .SH Name \fCnix-build\fR - build a Nix expression .SH Synopsis \fCnix-build\fR [\fIpaths…\fR] [\fC--arg\fR \fIname\fR \fIvalue\fR] [\fC--argstr\fR \fIname\fR \fIvalue\fR] [{\fC--attr\fR | \fC-A\fR} \fIattrPath\fR] [\fC--no-out-link\fR] [\fC--dry-run\fR] [{\fC--out-link\fR | \fC-o\fR} \fIoutlink\fR] .SH Description The \fCnix-build\fR command builds the derivations described by the Nix expressions in \fIpaths\fR. If the build succeeds, it places a symlink to the result in the current directory. The symlink is called \fCresult\fR. If there are multiple Nix expressions, or the Nix expressions evaluate to multiple derivations, multiple sequentially numbered symlinks are created (\fCresult\fR, \fCresult-2\fR, and so on). .PP If no \fIpaths\fR are specified, then \fCnix-build\fR will use \fCdefault.nix\fR in the current directory, if it exists. .PP If an element of \fIpaths\fR starts with \fChttp://\fR or \fChttps://\fR, it is interpreted as the URL of a tarball that will be downloaded and unpacked to a temporary location. The tarball must include a single top-level directory containing at least a file named \fCdefault.nix\fR. .PP \fCnix-build\fR is essentially a wrapper around \fB\fCnix-instantiate\fR\fR (\fInix-instantiate.md\fR) (to translate a high-level Nix expression to a low-level store derivation) and \fB\fCnix-store --realise\fR\fR (\fInix-store.md#operation---realise\fR) (to build the store derivation). .RS .PP \fBWarning\fR .PP The result of the build is automatically registered as a root of the Nix garbage collector. This root disappears automatically when the \fCresult\fR symlink is deleted or renamed. So don’t rename the symlink. .RE .SH Options All options not listed here are passed to \fCnix-store --realise\fR, except for \fC--arg\fR and \fC--attr\fR / \fC-A\fR which are passed to \fCnix-instantiate\fR. .IP "\(bu" 2 \fC--no-out-link\fR .br 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 \fCnix-store --gc\fR. .IP "\(bu" 2 \fC--dry-run\fR .br Show what store paths would be built or downloaded. .IP "\(bu" 2 \fC--out-link\fR / \fC-o\fR \fIoutlink\fR .br Change the name of the symlink to the output path created from \fCresult\fR to \fIoutlink\fR. .LP The following common options are supported: .SH Examples .LP .EX $ nix-build '' -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 .EE .PP If a derivation has multiple outputs, \fCnix-build\fR will build the default (first) output. You can also build all outputs: .LP .EX $ nix-build '' -A openssl.all .EE .PP This will create a symlink for each output named \fCresult-outputname\fR. The suffix is omitted if the output name is \fCout\fR. So if \fCopenssl\fR has outputs \fCout\fR, \fCbin\fR and \fCman\fR, \fCnix-build\fR will create symlinks \fCresult\fR, \fCresult-bin\fR and \fCresult-man\fR. It’s also possible to build a specific output: .LP .EX $ nix-build '' -A openssl.man .EE .PP This will create a symlink \fCresult-man\fR. .PP Build a Nix expression given on the command line: .LP .EX $ nix-build -E 'with import { }; runCommand \(dqfoo\(dq { } \(dqecho bar > $out\(dq' $ cat ./result bar .EE .PP Build the GNU Hello package from the latest revision of the master branch of Nixpkgs: .LP .EX $ nix-build https://github.com/NixOS/nixpkgs/archive/master.tar.gz -A hello .EE