Warning
This program is experimental and its interface is subject to change.
Name
nix - a tool for reproducible and declarative configuration management
Synopsis
nix [option...] subcommand
where subcommand is one of the following:
Main commands:
nix build- build a derivation or fetch a store pathnix develop- run a bash shell that provides the build environment of a derivationnix flake- manage Nix flakesnix help- show help aboutnixor a particular subcommandnix profile- manage Nix profilesnix repl- start an interactive environment for evaluating Nix expressionsnix run- run a Nix applicationnix search- search for packagesnix shell- run a shell in which the specified packages are available
Infrequently used commands:
nix bundle- bundle an application so that it works outside of the Nix storenix copy- copy paths between Nix storesnix edit- open the Nix expression of a Nix package in $EDITORnix eval- evaluate a Nix expressionnix fmt- reformat your code in the standard stylenix log- show the build log of the specified packages or paths, if availablenix path-info- query information about store pathsnix registry- manage the flake registrynix why-depends- show why a package has another package in its closure
Utility/scripting commands:
nix daemon- daemon to perform store operations on behalf of non-root clientsnix describe-stores- show registered store types and their available optionsnix hash- compute and convert cryptographic hashesnix key- generate and convert Nix signing keysnix nar- create or inspect NAR filesnix print-dev-env- print shell code that can be sourced by bash to reproduce the build environment of a derivationnix realisation- manipulate a Nix realisationnix show-config- show the Nix configurationnix show-derivation- show the contents of a store derivationnix store- manipulate a Nix store
Commands for upgrading or troubleshooting your Nix installation:
nix doctor- check your system for potential problems and print a PASS or FAIL for each checknix upgrade-nix- upgrade Nix to the stable version declared in Nixpkgs
Examples
-
Create a new flake:
# nix flake new hello # cd hello -
Build the flake in the current directory:
# nix build # ./result/bin/hello Hello, world! -
Run the flake in the current directory:
# nix run Hello, world! -
Start a development shell for hacking on this flake:
# nix develop # unpackPhase # cd hello-* # configurePhase # buildPhase # ./hello Hello, world! # installPhase # ../outputs/out/bin/hello Hello, world!
Description
Nix is a tool for building software, configurations and other artifacts in a reproducible and declarative way. For more information, see the Nix homepage or the Nix manual.
Installables
Many nix subcommands operate on one or more installables. These are
command line arguments that represent something that can be built in
the Nix store. Here are the recognised types of installables:
-
Flake output attributes:
nixpkgs#helloThese have the form flakeref[
#attrpath], where flakeref is a flake reference and attrpath is an optional attribute path. For more information on flakes, see thenix flakemanual page. Flake references are most commonly a flake identifier in the flake registry (e.g.nixpkgs), or a raw path (e.g./path/to/my-flakeor.or../foo), or a full URL (e.g.github:nixos/nixpkgsorpath:.)When the flake reference is a raw path (a path without any URL scheme), it is interpreted as a
path:orgit+file:url in the following way:-
If the path is within a Git repository, then the url will be of the form
git+file://[GIT_REPO_ROOT]?dir=[RELATIVE_FLAKE_DIR_PATH]whereGIT_REPO_ROOTis the path to the root of the git repository, andRELATIVE_FLAKE_DIR_PATHis the path (relative to the directory root) of the closest parent of the given path that contains aflake.nixwithin the git repository. If no such directory exists, then Nix will error-out.Note that the search will only include files indexed by git. In particular, files which are matched by
.gitignoreor have never beengit add-ed will not be available in the flake. If this is undesirable, specifypath:<directory>explicitly;For example, if
/foo/baris a git repository with the following structure:. └── baz ├── blah │ └── file.txt └── flake.nix
Then
/foo/bar/baz/blahwill resolve togit+file:///foo/bar?dir=baz-
If the supplied path is not a git repository, then the url will have the form
path:FLAKE_DIR_PATHwhereFLAKE_DIR_PATHis the closest parent of the supplied path that contains aflake.nixfile (within the same file-system). If no such directory exists, then Nix will error-out.For example, if
/foo/bar/flake.nixexists, then/foo/bar/baz/will resolve topath:/foo/bar
If attrpath is omitted, Nix tries some default values; for most subcommands, the default is
packages.system.default(e.g.packages.x86_64-linux.default), but some subcommands have other defaults. If attrpath is specified, attrpath is interpreted as relative to one or more prefixes; for most subcommands, these arepackages.system,legacyPackages.*system*and the empty prefix. Thus, onx86_64-linuxnix build nixpkgs#hellowill try to build the attributespackages.x86_64-linux.hello,legacyPackages.x86_64-linux.helloandhello. -
-
Store paths:
/nix/store/v5sv61sszx301i0x6xysaqzla09nksnd-hello-2.10These are paths inside the Nix store, or symlinks that resolve to a path in the Nix store.
-
Store derivations:
/nix/store/p7gp6lxdg32h4ka1q398wd9r2zkbbz2v-hello-2.10.drvBy default, if you pass a store derivation path to a
nixsubcommand, the command will operate on the output paths of the derivation.For example,
nix path-infoprints information about the output paths:# nix path-info --json /nix/store/p7gp6lxdg32h4ka1q398wd9r2zkbbz2v-hello-2.10.drv [{"path":"/nix/store/v5sv61sszx301i0x6xysaqzla09nksnd-hello-2.10",…}]If you want to operate on the store derivation itself, pass the
--derivationflag. -
Nix attributes:
--file /path/to/nixpkgs helloWhen the
-f/--filepath option is given, installables are interpreted as attribute paths referencing a value returned by evaluating the Nix file path. -
Nix expressions:
--expr '(import <nixpkgs> {}).hello.overrideDerivation (prev: { name = "my-hello"; })'.When the
--exproption is given, all installables are interpreted as Nix expressions. You may need to specify--impureif the expression references impure inputs (such as<nixpkgs>).
For most commands, if no installable is specified, the default is .,
i.e. Nix will operate on the default flake output attribute of the
flake in the current directory.
Derivation output selection
Derivations can have multiple outputs, each corresponding to a
different store path. For instance, a package can have a bin output
that contains programs, and a dev output that provides development
artifacts like C/C++ header files. The outputs on which nix commands
operate are determined as follows:
-
You can explicitly specify the desired outputs using the syntax installable
^output1,...,outputN. For example, you can obtain thedevandstaticoutputs of theglibcpackage:# nix build 'nixpkgs#glibc^dev,static' # ls ./result-dev/include/ ./result-static/lib/ …and likewise, using a store path to a "drv" file to specify the derivation:
# nix build '/nix/store/gzaflydcr6sb3567hap9q6srzx8ggdgg-glibc-2.33-78.drv^dev,static' … -
You can also specify that all outputs should be used using the syntax installable
^*. For example, the following shows the size of all outputs of theglibcpackage in the binary cache:# nix path-info -S --eval-store auto --store https://cache.nixos.org 'nixpkgs#glibc^*' /nix/store/g02b1lpbddhymmcjb923kf0l7s9nww58-glibc-2.33-123 33208200 /nix/store/851dp95qqiisjifi639r0zzg5l465ny4-glibc-2.33-123-bin 36142896 /nix/store/kdgs3q6r7xdff1p7a9hnjr43xw2404z7-glibc-2.33-123-debug 155787312 /nix/store/n4xa8h6pbmqmwnq0mmsz08l38abb06zc-glibc-2.33-123-static 42488328 /nix/store/q6580lr01jpcsqs4r5arlh4ki2c1m9rv-glibc-2.33-123-dev 44200560and likewise, using a store path to a "drv" file to specify the derivation:
# nix path-info -S '/nix/store/gzaflydcr6sb3567hap9q6srzx8ggdgg-glibc-2.33-78.drv^*' … -
If you didn't specify the desired outputs, but the derivation has an attribute
meta.outputsToInstall, Nix will use those outputs. For example, since the packagenixpkgs#libxml2has this attribute:# nix eval 'nixpkgs#libxml2.meta.outputsToInstall' [ "bin" "man" ]a command like
nix shell nixpkgs#libxml2will provide only those two outputs by default.Note that a store derivation (given by its
.drvfile store path) doesn't have any attributes likemeta, and thus this case doesn't apply to it. -
Otherwise, Nix will use all outputs of the derivation.
Nix stores
Most nix subcommands operate on a Nix store.
TODO: list store types, options
Options
Logging-related options:
-
--debugSet the logging verbosity level to 'debug'.
-
--log-formatformatSet the format of log output; one of
raw,internal-json,barorbar-with-logs. -
--print-build-logs/-LPrint full build logs on standard error.
-
--quietDecrease the logging verbosity level.
-
--verbose/-vIncrease the logging verbosity level.
Miscellaneous global options:
-
--helpShow usage information.
-
--offlineDisable substituters and consider all previously downloaded files up-to-date.
-
--optionname valueSet the Nix configuration setting name to value (overriding
nix.conf). -
--refreshConsider all previously downloaded files out-of-date.
-
--versionShow version information.
Options to override configuration settings:
-
--accept-flake-configEnable the
accept-flake-configsetting. -
--access-tokensvalueSet the
access-tokenssetting. -
--allow-dirtyEnable the
allow-dirtysetting. -
--allow-import-from-derivationEnable the
allow-import-from-derivationsetting. -
--allow-new-privilegesEnable the
allow-new-privilegessetting. -
--allow-symlinked-storeEnable the
allow-symlinked-storesetting. -
--allow-unsafe-native-code-during-evaluationEnable the
allow-unsafe-native-code-during-evaluationsetting. -
--allowed-impure-host-depsvalueSet the
allowed-impure-host-depssetting. -
--allowed-urisvalueSet the
allowed-urissetting. -
--allowed-usersvalueSet the
allowed-userssetting. -
--auto-allocate-uidsEnable the
auto-allocate-uidssetting. -
--auto-optimise-storeEnable the
auto-optimise-storesetting. -
--bash-promptvalueSet the
bash-promptsetting. -
--bash-prompt-prefixvalueSet the
bash-prompt-prefixsetting. -
--bash-prompt-suffixvalueSet the
bash-prompt-suffixsetting. -
--build-hookvalueSet the
build-hooksetting. -
--build-poll-intervalvalueSet the
build-poll-intervalsetting. -
--build-users-groupvalueSet the
build-users-groupsetting. -
--buildersvalueSet the
builderssetting. -
--builders-use-substitutesEnable the
builders-use-substitutessetting. -
--commit-lockfile-summaryvalueSet the
commit-lockfile-summarysetting. -
--compress-build-logEnable the
compress-build-logsetting. -
--connect-timeoutvalueSet the
connect-timeoutsetting. -
--coresvalueSet the
coressetting. -
--diff-hookvalueSet the
diff-hooksetting. -
--download-attemptsvalueSet the
download-attemptssetting. -
--download-speedvalueSet the
download-speedsetting. -
--eval-cacheEnable the
eval-cachesetting. -
--experimental-featuresvalueSet the
experimental-featuressetting. -
--extra-access-tokensvalueAppend to the
access-tokenssetting. -
--extra-allowed-impure-host-depsvalueAppend to the
allowed-impure-host-depssetting. -
--extra-allowed-urisvalueAppend to the
allowed-urissetting. -
--extra-allowed-usersvalueAppend to the
allowed-userssetting. -
--extra-experimental-featuresvalueAppend to the
experimental-featuressetting. -
--extra-extra-platformsvalueAppend to the
extra-platformssetting. -
--extra-hashed-mirrorsvalueAppend to the
hashed-mirrorssetting. -
--extra-ignored-aclsvalueAppend to the
ignored-aclssetting. -
--extra-nix-pathvalueAppend to the
nix-pathsetting. -
--extra-platformsvalueSet the
extra-platformssetting. -
--extra-plugin-filesvalueAppend to the
plugin-filessetting. -
--extra-sandbox-pathsvalueAppend to the
sandbox-pathssetting. -
--extra-secret-key-filesvalueAppend to the
secret-key-filessetting. -
--extra-substitutersvalueAppend to the
substituterssetting. -
--extra-system-featuresvalueAppend to the
system-featuressetting. -
--extra-trusted-public-keysvalueAppend to the
trusted-public-keyssetting. -
--extra-trusted-substitutersvalueAppend to the
trusted-substituterssetting. -
--extra-trusted-usersvalueAppend to the
trusted-userssetting. -
--fallbackEnable the
fallbacksetting. -
--filter-syscallsEnable the
filter-syscallssetting. -
--flake-registryvalueSet the
flake-registrysetting. -
--fsync-metadataEnable the
fsync-metadatasetting. -
--gc-reserved-spacevalueSet the
gc-reserved-spacesetting. -
--hashed-mirrorsvalueSet the
hashed-mirrorssetting. -
--http-connectionsvalueSet the
http-connectionssetting. -
--http2Enable the
http2setting. -
--id-countvalueSet the
id-countsetting. -
--ignore-tryEnable the
ignore-trysetting. -
--ignored-aclsvalueSet the
ignored-aclssetting. -
--impersonate-linux-26Enable the
impersonate-linux-26setting. -
--keep-build-logEnable the
keep-build-logsetting. -
--keep-derivationsEnable the
keep-derivationssetting. -
--keep-env-derivationsEnable the
keep-env-derivationssetting. -
--keep-failedEnable the
keep-failedsetting. -
--keep-goingEnable the
keep-goingsetting. -
--keep-outputsEnable the
keep-outputssetting. -
--log-linesvalueSet the
log-linessetting. -
--max-build-log-sizevalueSet the
max-build-log-sizesetting. -
--max-freevalueSet the
max-freesetting. -
--max-jobsvalueSet the
max-jobssetting. -
--max-silent-timevalueSet the
max-silent-timesetting. -
--min-freevalueSet the
min-freesetting. -
--min-free-check-intervalvalueSet the
min-free-check-intervalsetting. -
--nar-buffer-sizevalueSet the
nar-buffer-sizesetting. -
--narinfo-cache-negative-ttlvalueSet the
narinfo-cache-negative-ttlsetting. -
--narinfo-cache-positive-ttlvalueSet the
narinfo-cache-positive-ttlsetting. -
--netrc-filevalueSet the
netrc-filesetting. -
--nix-pathvalueSet the
nix-pathsetting. -
--no-accept-flake-configDisable the
accept-flake-configsetting. -
--no-allow-dirtyDisable the
allow-dirtysetting. -
--no-allow-import-from-derivationDisable the
allow-import-from-derivationsetting. -
--no-allow-new-privilegesDisable the
allow-new-privilegessetting. -
--no-allow-symlinked-storeDisable the
allow-symlinked-storesetting. -
--no-allow-unsafe-native-code-during-evaluationDisable the
allow-unsafe-native-code-during-evaluationsetting. -
--no-auto-allocate-uidsDisable the
auto-allocate-uidssetting. -
--no-auto-optimise-storeDisable the
auto-optimise-storesetting. -
--no-builders-use-substitutesDisable the
builders-use-substitutessetting. -
--no-compress-build-logDisable the
compress-build-logsetting. -
--no-eval-cacheDisable the
eval-cachesetting. -
--no-fallbackDisable the
fallbacksetting. -
--no-filter-syscallsDisable the
filter-syscallssetting. -
--no-fsync-metadataDisable the
fsync-metadatasetting. -
--no-http2Disable the
http2setting. -
--no-ignore-tryDisable the
ignore-trysetting. -
--no-impersonate-linux-26Disable the
impersonate-linux-26setting. -
--no-keep-build-logDisable the
keep-build-logsetting. -
--no-keep-derivationsDisable the
keep-derivationssetting. -
--no-keep-env-derivationsDisable the
keep-env-derivationssetting. -
--no-keep-failedDisable the
keep-failedsetting. -
--no-keep-goingDisable the
keep-goingsetting. -
--no-keep-outputsDisable the
keep-outputssetting. -
--no-preallocate-contentsDisable the
preallocate-contentssetting. -
--no-print-missingDisable the
print-missingsetting. -
--no-pure-evalDisable the
pure-evalsetting. -
--no-require-sigsDisable the
require-sigssetting. -
--no-restrict-evalDisable the
restrict-evalsetting. -
--no-run-diff-hookDisable the
run-diff-hooksetting. -
--no-sandboxDisable sandboxing.
-
--no-sandbox-fallbackDisable the
sandbox-fallbacksetting. -
--no-show-traceDisable the
show-tracesetting. -
--no-substituteDisable the
substitutesetting. -
--no-sync-before-registeringDisable the
sync-before-registeringsetting. -
--no-trace-function-callsDisable the
trace-function-callssetting. -
--no-trace-verboseDisable the
trace-verbosesetting. -
--no-use-case-hackDisable the
use-case-hacksetting. -
--no-use-cgroupsDisable the
use-cgroupssetting. -
--no-use-registriesDisable the
use-registriessetting. -
--no-use-sqlite-walDisable the
use-sqlite-walsetting. -
--no-warn-dirtyDisable the
warn-dirtysetting. -
--plugin-filesvalueSet the
plugin-filessetting. -
--post-build-hookvalueSet the
post-build-hooksetting. -
--pre-build-hookvalueSet the
pre-build-hooksetting. -
--preallocate-contentsEnable the
preallocate-contentssetting. -
--print-missingEnable the
print-missingsetting. -
--pure-evalEnable the
pure-evalsetting. -
--relaxed-sandboxEnable sandboxing, but allow builds to disable it.
-
--require-sigsEnable the
require-sigssetting. -
--restrict-evalEnable the
restrict-evalsetting. -
--run-diff-hookEnable the
run-diff-hooksetting. -
--sandboxEnable sandboxing.
-
--sandbox-build-dirvalueSet the
sandbox-build-dirsetting. -
--sandbox-dev-shm-sizevalueSet the
sandbox-dev-shm-sizesetting. -
--sandbox-fallbackEnable the
sandbox-fallbacksetting. -
--sandbox-pathsvalueSet the
sandbox-pathssetting. -
--secret-key-filesvalueSet the
secret-key-filessetting. -
--show-traceEnable the
show-tracesetting. -
--stalled-download-timeoutvalueSet the
stalled-download-timeoutsetting. -
--start-idvalueSet the
start-idsetting. -
--storevalueSet the
storesetting. -
--substituteEnable the
substitutesetting. -
--substitutersvalueSet the
substituterssetting. -
--sync-before-registeringEnable the
sync-before-registeringsetting. -
--systemvalueSet the
systemsetting. -
--system-featuresvalueSet the
system-featuressetting. -
--tarball-ttlvalueSet the
tarball-ttlsetting. -
--timeoutvalueSet the
timeoutsetting. -
--trace-function-callsEnable the
trace-function-callssetting. -
--trace-verboseEnable the
trace-verbosesetting. -
--trusted-public-keysvalueSet the
trusted-public-keyssetting. -
--trusted-substitutersvalueSet the
trusted-substituterssetting. -
--trusted-usersvalueSet the
trusted-userssetting. -
--use-case-hackEnable the
use-case-hacksetting. -
--use-cgroupsEnable the
use-cgroupssetting. -
--use-registriesEnable the
use-registriessetting. -
--use-sqlite-walEnable the
use-sqlite-walsetting. -
--user-agent-suffixvalueSet the
user-agent-suffixsetting. -
--warn-dirtyEnable the
warn-dirtysetting.