nix3-build(1)
π nix3-build β build a derivation or fetch a store path
Ok bestie, this is nix3-build, straight out of the General Commands Manual (that's the manual name, we're keeping that info). It's the command you use when you want Nix to actually make the thing. Buckle up. π
β οΈ Warning β οΈ This program is experimental and its interface is subject to change. Like, don't build your whole personality on it staying the same, mkay? π«
β¨ Name β¨
nix build β build a derivation or fetch a store path. That's it. That's the whole vibe. π
πΈ Synopsis πΈ
nix build [optionβ¦] installablesβ¦
π¦ Examples π¦
- Build the default package from the flake in the current directory:
# nix build
- Build and run GNU Hello from the
nixpkgsflake:
# nix build nixpkgs#hello
# ./result/bin/hello
Hello, world!
- Build GNU Hello and Cowsay, leaving two result symlinks:
# nix build nixpkgs#hello nixpkgs#cowsay
# ls -l result*
lrwxrwxrwx 1 β¦ result -> /nix/store/10l19qifk7hjjq47px8m2prqk1gv4isy-hello-2.10
lrwxrwxrwx 1 β¦ result-1 -> /nix/store/frzgk3v1ycnarpfc2rkynravng27a86d-cowsay-3.03+dfsg2
- Build GNU Hello and print the resulting store path.
# nix build nixpkgs#hello --print-out-paths
/nix/store/10l19qifk7hjjq47px8m2prqk1gv4isy-hello-2.10
- Build a specific output:
# nix build nixpkgs#glibc.dev
# ls -ld ./result-dev
lrwxrwxrwx 1 β¦ ./result-dev -> /nix/store/hb4lb9n3gv855llky72hrs4pglpxq70m-glibc-2.32-dev
- Build all outputs:
# nix build "nixpkgs#openssl^*" --print-out-paths
/nix/store/ah1slww3lfsj02w563wjf1xcz5fayj36-openssl-3.0.13-bin
/nix/store/vswlynn75s0bpba3vl6bi3wyzjym95yi-openssl-3.0.13-debug
/nix/store/z71nwwni9dcxdmd3v3a7j24v70c7v7z3-openssl-3.0.13-dev
/nix/store/iabzsa5c73p4f10zfmf5r2qsrn0hl4lk-openssl-3.0.13-doc
/nix/store/zqmfrpxvcll69a2lyawnpvp15zh421v2-openssl-3.0.13-man
/nix/store/l3nlzki957anyy7yb25qvwk6cqrnvb67-openssl-3.0.13
- Build attribute
build.x86_64-linuxfrom (non-flake) Nix expressionrelease.nix:
# nix build --file release.nix build.x86_64-linux
- Build a NixOS system configuration from a flake, and make a profile point to the result:
# nix build --profile /nix/var/nix/profiles/system \
~/my-configurations#nixosConfigurations.machine.config.system.build.toplevel
(This is essentially what nixos-rebuild does.)
- Build an expression specified on the command line:
# nix build --impure --expr \
'with import <nixpkgs> {};
runCommand "foo" {
buildInputs = [ hello ];
}
"hello > $out"'
# cat ./result
Hello, world!
Note that --impure is needed because we're using <nixpkgs>, which relies on the $NIX_PATH environment variable. π
- Fetch a store path from the configured substituters, if it doesn't already exist:
# nix build /nix/store/frzgk3v1ycnarpfc2rkynravng27a86d-cowsay-3.03+dfsg2
π Description π
nix build builds the specified installables. Installables that resolve to derivations get built (or substituted if that's possible π). Store path installables get substituted.
Unless --no-link is specified, after a successful build it creates symlinks to the store paths of the installables. These symlinks have the prefix ./result by default β you can override that with the --out-link option, no stress. β¨
Each symlink has a suffix -<N>-<outname>, where:
Nis the index of the installable (with the left-most installable having index0), andoutnameis the symbolic derivation output name (e.g.bin,devorlib).
-<N> is omitted if N = 0, and -<outname> is omitted if outname = out (which denotes the default output). So basically Nix is out here being efficient with names. periodt. π
β¨ OPTIONS β¨
--dry-runβ Show what this command would do without doing it. A little preview, a little dress rehearsal. π--jsonβ Produce output in JSON format, suitable for consumption by another program. Feed it to your script bestie. π€--no-linkβ Do not create symlinks to the build results.--no-prettyβ Print compact JSON output on a single line, even when the output is a terminal. Some commands may print multiple JSON objects on separate lines.
See --pretty.
--out-link/-opath β Use path as prefix for the symlinks to the build results. It defaults toresult.--prettyβ Print multi-line, indented JSON output for readability.
Default: indent if output is to a terminal.
This option is only effective when --json is also specified.
--print-out-pathsβ Print the resulting output paths--profilepath β The profile to operate on.--rebuildβ Rebuild an already built package and compare the result to the existing store paths. π--stdinβ Read installables from the standard input. No default installable applied.
π Common evaluation options π
--argname expr β Pass the value expr as the argument name to Nix functions.--arg-from-filename path β Pass the contents of file path as the argument name to Nix functions.--arg-from-stdinname β Pass the contents of stdin as the argument name to Nix functions.--argstrname string β Pass the string string as the argument name to Nix functions.--debuggerβ Start an interactive environment if evaluation fails. π--eval-storestore-url β The URL of the Nix store to use for evaluation, i.e. to store derivations (.drvfiles) and inputs referenced by them.--impureβ Allow access to mutable paths and repositories. π--include/-Ipath β Add path to search path entries used to resolve lookup paths
This option may be given multiple times.
Paths added through -I take precedence over the nix-path configuration setting and the NIX_PATH environment variable.
--override-flakeoriginal-ref resolved-ref β Override the flake registries, redirecting original-ref to resolved-ref.
π Common flake-related options π
--commit-lock-fileβ Commit changes to the flake's lock file.--inputs-fromflake-url β Use the inputs of the specified flake as registry entries.--no-registriesβ Don't allow lookups in the flake registries.
DEPRECATED Use --no-use-registries instead.
--no-update-lock-fileβ Do not allow any updates to the flake's lock file.--no-write-lock-fileβ Do not write the flake's newly generated lock file.--output-lock-fileflake-lock-path β Write the given lock file instead offlake.lockwithin the top-level flake.--override-inputinput-path flake-url β Override a specific flake input (e.g.dwarffs/nixpkgs). The input path must not be empty. This implies--no-write-lock-file.--recreate-lock-fileβ Recreate the flake's lock file from scratch.
DEPRECATED Use nix flake update instead.
--reference-lock-fileflake-lock-path β Read the given lock file instead offlake.lockwithin the top-level flake.--update-inputinput-path β Update a specific flake input (ignoring its previous entry in the lock file).
DEPRECATED Use nix flake update instead.
π Logging-related options π
--debugβ Set the logging verbosity level to 'debug'. π--log-formatformat β Set the format of log output; one ofraw,internal-json,barorbar-with-logs.--print-build-logs/-Lβ Print full build logs on standard error.--quietβ Decrease the logging verbosity level. π€«--verbose/-vβ Increase the logging verbosity level. π’
π§ Miscellaneous global options π§
--helpβ Show usage information.--offlineβ Disable substituters and consider all previously downloaded files up-to-date.--optionname value β Set the Nix configuration setting name to value (overridingnix.conf).--refreshβ Consider all previously downloaded files out-of-date.--repairβ During evaluation, rewrite missing or corrupted files in the Nix store. During building, rebuild missing or corrupted store paths. π©Ή--versionβ Show version information.
π Options that change the interpretation of installables π
--exprexpr β Interpret installables as attribute paths relative to the Nix expression expr.--file/-ffile β Interpret installables as attribute paths relative to the Nix expression stored in file. If file is the character-, then a Nix expression is read from standard input. Implies--impure.
Note See man nix.conf for overriding configuration settings with command line flags.
And that's the whole page, bestie!! π«Άπ Source-wise, this is nix3-build(1) from the General Commands Manual β you know, the one that lives in your terminal and keeps the receipts. Go forth and build something iconic. β¨ππ
π¦ where this page comes from
- fedora 44: nix-core 2.35.3-2.fc44 Β· LGPL-2.1-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms