2020-07-24 13:56:19 +03:00
|
|
|
|
# Name
|
2020-07-23 13:58:42 +03:00
|
|
|
|
|
2020-07-24 13:56:19 +03:00
|
|
|
|
`nix-build` - build a Nix expression
|
2020-07-23 13:58:42 +03:00
|
|
|
|
|
2020-07-24 13:56:19 +03:00
|
|
|
|
# Synopsis
|
2020-07-23 13:58:42 +03:00
|
|
|
|
|
2020-07-24 13:56:19 +03:00
|
|
|
|
`nix-build` [*paths…*]
|
|
|
|
|
[`--arg` *name* *value*]
|
|
|
|
|
[`--argstr` *name* *value*]
|
|
|
|
|
[{`--attr` | `-A`} *attrPath*]
|
|
|
|
|
[`--no-out-link`]
|
|
|
|
|
[`--dry-run`]
|
|
|
|
|
[{`--out-link` | `-o`} *outlink*]
|
2020-07-23 13:58:42 +03:00
|
|
|
|
|
2022-06-04 00:19:12 +03:00
|
|
|
|
# Disambiguation
|
|
|
|
|
|
|
|
|
|
This man page describes the command `nix-build`, which is distinct from `nix
|
|
|
|
|
build`. For documentation on the latter, run `nix build --help` or see `man
|
|
|
|
|
nix3-build`.
|
|
|
|
|
|
2020-07-23 13:58:42 +03:00
|
|
|
|
# Description
|
|
|
|
|
|
|
|
|
|
The `nix-build` command builds the derivations described by the Nix
|
2020-07-23 15:28:05 +03:00
|
|
|
|
expressions in *paths*. If the build succeeds, it places a symlink to
|
|
|
|
|
the result in the current directory. The symlink is called `result`. If
|
2020-07-23 13:58:42 +03:00
|
|
|
|
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).
|
|
|
|
|
|
2020-07-23 15:28:05 +03:00
|
|
|
|
If no *paths* are specified, then `nix-build` will use `default.nix` in
|
2020-07-23 13:58:42 +03:00
|
|
|
|
the current directory, if it exists.
|
|
|
|
|
|
2020-07-23 15:28:05 +03:00
|
|
|
|
If an element of *paths* starts with `http://` or `https://`, it is
|
2020-07-23 13:58:42 +03:00
|
|
|
|
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 `default.nix`.
|
|
|
|
|
|
|
|
|
|
`nix-build` is essentially a wrapper around
|
2020-07-24 16:46:16 +03:00
|
|
|
|
[`nix-instantiate`](nix-instantiate.md) (to translate a high-level Nix
|
2022-12-20 16:37:40 +02:00
|
|
|
|
expression to a low-level [store derivation]) and [`nix-store
|
2023-03-23 17:27:41 +02:00
|
|
|
|
--realise`](@docroot@/command-ref/nix-store/realise.md) (to build the store
|
2020-07-24 16:46:16 +03:00
|
|
|
|
derivation).
|
2020-07-23 13:58:42 +03:00
|
|
|
|
|
2022-12-20 16:37:40 +02:00
|
|
|
|
[store derivation]: ../glossary.md#gloss-store-derivation
|
|
|
|
|
|
2020-07-23 13:58:42 +03:00
|
|
|
|
> **Warning**
|
2020-07-24 13:56:19 +03:00
|
|
|
|
>
|
2020-07-23 13:58:42 +03:00
|
|
|
|
> 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.
|
|
|
|
|
|
|
|
|
|
# Options
|
|
|
|
|
|
2023-03-23 17:27:41 +02:00
|
|
|
|
All options not listed here are passed to `nix-store --realise`,
|
|
|
|
|
except for `--arg` and `--attr` / `-A` which are passed to `nix-instantiate`.
|
2020-07-23 13:58:42 +03:00
|
|
|
|
|
2022-12-07 17:12:26 +02:00
|
|
|
|
- <span id="opt-no-out-link">[`--no-out-link`](#opt-no-out-link)<span>
|
|
|
|
|
|
2020-07-23 13:58:42 +03:00
|
|
|
|
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
|
2022-12-07 17:12:26 +02:00
|
|
|
|
might be deleted by `nix-store --gc`.
|
|
|
|
|
|
|
|
|
|
- <span id="opt-dry-run">[`--dry-run`](#opt-dry-run)</span>
|
2020-07-23 13:58:42 +03:00
|
|
|
|
|
|
|
|
|
Show what store paths would be built or downloaded.
|
|
|
|
|
|
2022-12-07 17:12:26 +02:00
|
|
|
|
- <span id="opt-out-link">[`--out-link`](#opt-out-link)</span> / `-o` *outlink*
|
|
|
|
|
|
2020-07-23 13:58:42 +03:00
|
|
|
|
Change the name of the symlink to the output path created from
|
2020-07-23 15:28:05 +03:00
|
|
|
|
`result` to *outlink*.
|
2020-07-23 13:58:42 +03:00
|
|
|
|
|
2023-03-23 17:27:41 +02:00
|
|
|
|
{{#include ./opt-common.md}}
|
|
|
|
|
|
|
|
|
|
{{#include ./env-common.md}}
|
2020-07-23 13:58:42 +03:00
|
|
|
|
|
|
|
|
|
# Examples
|
|
|
|
|
|
2020-07-31 16:43:25 +03:00
|
|
|
|
```console
|
2023-04-30 16:52:38 +03:00
|
|
|
|
$ nix-build '<nixpkgs>' --attr firefox
|
2020-07-31 16:43:25 +03:00
|
|
|
|
store derivation is /nix/store/qybprl8sz2lc...-firefox-1.5.0.7.drv
|
|
|
|
|
/nix/store/d18hyl92g30l...-firefox-1.5.0.7
|
2020-07-24 13:56:19 +03:00
|
|
|
|
|
2020-07-31 16:43:25 +03:00
|
|
|
|
$ ls -l result
|
|
|
|
|
lrwxrwxrwx ... result -> /nix/store/d18hyl92g30l...-firefox-1.5.0.7
|
2020-07-24 13:56:19 +03:00
|
|
|
|
|
2020-07-31 16:43:25 +03:00
|
|
|
|
$ ls ./result/bin/
|
|
|
|
|
firefox firefox-config
|
|
|
|
|
```
|
2020-07-23 13:58:42 +03:00
|
|
|
|
|
|
|
|
|
If a derivation has multiple outputs, `nix-build` will build the default
|
|
|
|
|
(first) output. You can also build all outputs:
|
|
|
|
|
|
2020-07-31 16:43:25 +03:00
|
|
|
|
```console
|
2023-04-30 16:52:38 +03:00
|
|
|
|
$ nix-build '<nixpkgs>' --attr openssl.all
|
2020-07-31 16:43:25 +03:00
|
|
|
|
```
|
2020-07-23 13:58:42 +03:00
|
|
|
|
|
|
|
|
|
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:
|
|
|
|
|
|
2020-07-31 16:43:25 +03:00
|
|
|
|
```console
|
2023-04-30 16:52:38 +03:00
|
|
|
|
$ nix-build '<nixpkgs>' --attr openssl.man
|
2020-07-31 16:43:25 +03:00
|
|
|
|
```
|
2020-07-23 13:58:42 +03:00
|
|
|
|
|
|
|
|
|
This will create a symlink `result-man`.
|
|
|
|
|
|
|
|
|
|
Build a Nix expression given on the command line:
|
|
|
|
|
|
2020-07-31 16:43:25 +03:00
|
|
|
|
```console
|
2023-04-30 16:52:38 +03:00
|
|
|
|
$ nix-build --expr 'with import <nixpkgs> { }; runCommand "foo" { } "echo bar > $out"'
|
2020-07-31 16:43:25 +03:00
|
|
|
|
$ cat ./result
|
|
|
|
|
bar
|
|
|
|
|
```
|
2020-07-23 13:58:42 +03:00
|
|
|
|
|
|
|
|
|
Build the GNU Hello package from the latest revision of the master
|
|
|
|
|
branch of Nixpkgs:
|
|
|
|
|
|
2020-07-31 16:43:25 +03:00
|
|
|
|
```console
|
2023-04-30 16:52:38 +03:00
|
|
|
|
$ nix-build https://github.com/NixOS/nixpkgs/archive/master.tar.gz --attr hello
|
2020-07-31 16:43:25 +03:00
|
|
|
|
```
|