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 nixpkgs flake:
# 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-linux from (non-flake) Nix expression release.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:

  • N is the index of the installable (with the left-most installable having index 0), and
  • outname is the symbolic derivation output name (e.g. bin, dev or lib).

-<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 / -o path β€” Use path as prefix for the symlinks to the build results. It defaults to result.
  • --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
  • --profile path β€” 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 πŸŽ€

  • --arg name expr β€” Pass the value expr as the argument name to Nix functions.
  • --arg-from-file name path β€” Pass the contents of file path as the argument name to Nix functions.
  • --arg-from-stdin name β€” Pass the contents of stdin as the argument name to Nix functions.
  • --argstr name string β€” Pass the string string as the argument name to Nix functions.
  • --debugger β€” Start an interactive environment if evaluation fails. πŸ”
  • --eval-store store-url β€” The URL of the Nix store to use for evaluation, i.e. to store derivations (.drv files) and inputs referenced by them.
  • --impure β€” Allow access to mutable paths and repositories. 😈
  • --include / -I path β€” 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-flake original-ref resolved-ref β€” Override the flake registries, redirecting original-ref to resolved-ref.
  • --commit-lock-file β€” Commit changes to the flake's lock file.
  • --inputs-from flake-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-file flake-lock-path β€” Write the given lock file instead of flake.lock within the top-level flake.
  • --override-input input-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-file flake-lock-path β€” Read the given lock file instead of flake.lock within the top-level flake.
  • --update-input input-path β€” Update a specific flake input (ignoring its previous entry in the lock file).
DEPRECATED Use nix flake update instead.
  • --debug β€” Set the logging verbosity level to 'debug'. πŸ›
  • --log-format format β€” Set the format of log output; one of raw, internal-json, bar or bar-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.
  • --option name value β€” Set the Nix configuration setting name to value (overriding nix.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 πŸ’œ

  • --expr expr β€” Interpret installables as attribute paths relative to the Nix expression expr.
  • --file / -f file β€” 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