NIX-STORE-REALISE(1)
π nix-store --realise(1) π
General Commands Manual has entered the chat, and bestieβ¦ it's giving build or fetch store objects energy. No cap. Let's get into it. π
πΈ Name πΈ
nix-store --realise - build or fetch store objects
β¨ Synopsis β¨
nix-store {--realise | -r} paths⦠[--dry-run]
π Description π
Okay so every one of paths is processed like this:
- If the path leads to a store derivation:
- If it is not valid, substitute the store derivation file itself.
- Realise its output paths:
- Try to fetch from substituters the store objects associated with the output paths in the store derivation's closure.
- With content-addressing derivations: Determine the output paths to realise by querying content-addressed realisation entries in the Nix database.
- For any store paths that cannot be substituted, produce the required store objects:
- Realise all outputs of the derivation's dependencies.
- Run the derivation's builder executable.
- Try to fetch from substituters the store objects associated with the output paths in the store derivation's closure.
- Otherwise, and if the path is not already valid: Try to fetch the associated store objects in the path's closure from substituters.
If no substitutes are available and no store derivation is given, realisation fails.
The resulting paths are printed on standard output. For non-derivation arguments, the argument itself is printed.
π¨ Special exit codes for build failure π¨
The 1xx status codes are used when requested builds failed. The following codes are in use:
100Generic build failure β The builder process returned with a non-zero exit code.101Build timeout β The build was aborted because it did not complete within the specified timeout.102Hash mismatch β The build output was rejected because it does not match theoutputHashattribute of the derivation.104Not deterministic β The build succeeded in check mode but the resulting output is not binary reproducible.
With the --keep-going flag it's possible for multiple failures to occur. In this case the 1xx status codes are or combined using bitwise OR.
0b1100100
^^^^
|||`- timeout
||`-- output hash mismatch
|`--- build failure
`---- not deterministic
π Options π
--dry-runβ Print on standard error a description of what packages would be built or downloaded, without actually performing the operation.--ignore-unknownβ If a non-derivation path does not have a substitute, then silently ignore it.--checkβ This option allows you to check whether a derivation is deterministic. It rebuilds the specified derivation and checks whether the result is bitwise-identical with the existing outputs, printing an error if thatβs not the case. The outputs of the specified derivation must already exist. When used with-K, if an output path is not identical to the corresponding output from the previous build, the new output path is left in/nix/store/name.check.
π Options π (the ones allowed for all nix-store operations)
The following options are allowed for all nix-store operations, but may not always have an effect.
--add-rootpath β Causes the result of a realisation (--realiseand--force-realise) to be registered as a root of the garbage collector.pathwill be created as a symlink to the resulting store path. In addition, a uniquely named symlink topathwill be created in/nix/var/nix/gcroots/auto/. For instance,
$ nix-store --add-root /home/eelco/bla/result --realise ...
$ ls -l /nix/var/nix/gcroots/auto
lrwxrwxrwx 1 ... 2005-03-13 21:10 dn54lcypm8f8... -> /home/eelco/bla/result
$ ls -l /home/eelco/bla/result
lrwxrwxrwx 1 ... 2005-03-13 21:10 /home/eelco/bla/result -> /nix/store/1r11343n6qd4...-f-spot-0.0.10
Thus, when /home/eelco/bla/result is removed, the GC root in the auto directory becomes a dangling symlink and will be ignored by the collector.
π¨ Warning π¨ Note that it is not possible to move or rename GC roots, since the symlink in the auto directory will still point to the old location.
If there are multiple results, then multiple symlinks will be created by sequentially numbering symlinks beyond the first one (e.g., foo, foo-2, foo-3, and so on).
β¨ COMMON OPTIONS β¨
okay so bestie, listen π most Nix commands take these bad boys right here. they're the shared wardrobe, the communal snack drawer, the universal vibe. let's go one by one, no skipping, no skimming, periodt.
--helpβ prints a lil summary of the command syntax and then dips out. that's it, that's the whole thing π«Ά--versionβ prints the Nix version number on standard output and exits. iconic, brief, slays.--verbose,-vβ turns up the volume on the diagnostic messages printed to standard error. here's the deal: for every Nix operation, whatever shows up on standard output is well-defined, and any diagnostic tea gets spilled on standard error, never on standard output. you can pass this option over and over again, and each time it stacks π
currently these are the verbosity levels that exist:
- 0 βErrors onlyβ β only prints messages telling you why the Nix invocation flopped. nothing else, no commentary π
- 1 βInformationalβ β prints actually useful messages about what Nix is up to. this is the default, so this is the baseline reality you live in.
- 2 βTalkativeβ β more informational messages. it's yapping now, affectionately.
- 3 βChattyβ β even more informational messages. the yapping has escalated πΈ
- 4 βDebugβ β prints debug information. we're in the engine room now.
- 5 βVomitβ β prints vast amounts of debug information. truly unhinged quantities. you asked for this π
--quietβ turns the volume down on diagnostic messages printed to standard error. it's the inverse option to-v/--verbose. also stackable, so you can pass it repeatedly, and it walks back down the verbosity levels list from up above.--log-formatformat β changes how the log output is formatted, where format is one of these:rawβ the raw format, exactly as outputted bynix-build.internal-jsonβ outputs the logs in a structured manner.
Warning β οΈ while the schema itself is relatively stable, the format of the error-messages (namely of the msg-field) can change between releases. so like, don't hardcode your whole personality around parsing it, bestie.
barβ only displays a progress bar while the builds are happening. minimal, clean, a vibe.bar-with-logsβ displays the raw logs, with the progress bar chillin' at the bottom.
--no-build-output,-Qβ by default, whatever the builders write to standard output and standard error gets echoed to the Nix command's standard error. this option suppresses that behaviour entirely, shhh π€« note that the builder's standard output and error are always written to a log file inprefix/nix/var/log/nixno matter what. the receipts are eternal.--max-jobs,-jnumber β sets the maximum number of build jobs Nix will run in parallel to the number you give it. you can literally sayautoto use however many CPUs the system has. the default comes from themax-jobsconfiguration setting, which itself defaults to1. a higher value is a good move on SMP systems, or when you wanna exploit I/O latency like the main character you are π₯
setting it to 0 disallows building on the local machine at all β which is exactly what you want when you only want builds happening on remote builders.
--coresβ sets the value of theNIX_BUILD_CORESenvironment variable in the invocation of builders. builders can use this variable however they please to control the maximum amount of parallelism. for instance, in Nixpkgs, if the derivation attributeenableParallelBuildingis set totrue, the builder passes the-jNflag to GNU Make. it defaults to the value of thecoresconfiguration setting, if that's set β otherwise1. the value0means the builder should use all available CPU cores in the system. go wild π--max-silent-timeβ sets the maximum number of seconds a builder can go without producing any data on standard output or standard error before it gets timed out. the default comes from themax-silent-timeconfiguration setting.0means no time-out. the silence can continue forever, apparently.--timeoutβ sets the maximum number of seconds a builder can run. the default comes from thetimeoutconfiguration setting.0means no timeout. zero is doing a lot of heavy lifting in this section honestly.--keep-going,-kβ keep going even when builds fail, to the greatest extent possible. like, if building an input of some derivation fails, Nix will still build the other inputs β but not the derivation itself. without this option, Nix stops if any build fails (except for builds of substitutes), and it might even kill builds that are already in progress (in the case of parallel or distributed builds). ruthless π--keep-failed,-Kβ says that when a build fails, the temporary directory where the build took place (usually in/tmp) should not be deleted. the path of the build directory gets printed as an informational message, so you can go poke around the crime scene π--fallbackβ whenever Nix tries to build a derivation where substitutes are known for every output path, but realising those output paths through the substitutes fails, fall back on actually building the derivation.
the most common scenario where this hits is when we have registered substitutes so we can do binary distribution from, like, a network repository. if that repository is down, realising the derivation will fail. with this option specified, Nix just builds the derivation instead. so basically: installation from binaries falls back on installation from source π¦
this is not the default, and here's why β it's generally not desirable for a transient failure in getting the substitutes to lead to a full build from source (and the whole associated resource consumption that comes with it). so it's a choice, not a lifestyle.
--readonly-modeβ when this is used, no attempt is made to open the Nix database. most Nix operations genuinely do need database access, so those operations are gonna fail. fair warning π«--argname value β this option is accepted bynix-env,nix-instantiate,nix-shellandnix-build. when evaluating Nix expressions, the expression evaluator will automatically try to call functions that it encounters. it can automatically call functions where every argument has a default value (e.g.,{ argName ? defaultValue }: ...).
with --arg, you can also call functions that have arguments without a default value (or override a default value). so like: if the evaluator encounters a function with an argument named name, it will call it with value as the value.
for instance, the top-level default.nix in Nixpkgs is actually a function:
{ # The system (e.g., `i686-linux') for which to build the packages.
system ? builtins.currentSystem
...
}: ...
so if you call this Nix expression (e.g., when you do nix-env --install --attr pkgname), the function gets called automatically using the value builtins.currentSystem for the system argument. you can override it using --arg, e.g., nix-env --install --attr pkgname --arg system "i686-freebsd". (note that since the argument is a Nix string literal, you have to escape the quotes, bestie β the shell will absolutely not be nice to you otherwise π)
--arg-from-filename path β pass the contents of the file at path as the argument name to Nix functions. file goes in, argument comes out β¨--arg-from-stdinname β pass the contents of stdin as the argument name to Nix functions. pipe it in, babe π--argstrname value β this is like--arg, except the value is not a Nix expression, it's a string. so instead of--arg system "i686-linux"(the outer quotes are there to keep the shell happy), you can just say--argstr system i686-linux. so much less quoting drama π--attr,-AattrPath β select an attribute from the top-level Nix expression being evaluated. (nix-env,nix-instantiate,nix-buildandnix-shellonly.) the attribute path attrPath is a sequence of attribute names separated by dots. for instance, given a top-level Nix expression e, the attribute pathxorg.xorgserverwould cause the expressione.xorg.xorgserverto be used. seenix-env --installfor some concrete examples.
in addition to attribute names, you can also specify array indices. for instance, the attribute path foo.3.bar selects the bar attribute of the fourth element of the array in the foo attribute of the top-level expression. yes, indices are zero-based, yes it's 3 for the fourth one, don't think about it too hard, just trust π
--eval-storestore-url β the URL to the Nix store to use for evaluation, i.e. where to store derivations (.drvfiles) and inputs referenced by them.--expr,-Eβ interpret the command line arguments as a list of Nix expressions to be parsed and evaluated, rather than as a list of file names of Nix expressions. (nix-instantiate,nix-buildandnix-shellonly.)
for nix-shell, this option is commonly used to give you a shell in which you can build the packages returned by the expression. if you want a shell that contains the built packages ready for use, give your expression to the nix-shell --packages convenience flag instead. different tool, different result, don't mix them up π«Ά
-I,--includepath β add an entry to the list of search paths used to resolve lookup paths. this option can be given multiple times. stack 'em up π
paths added through -I take precedence over the nix-path configuration setting and the NIX_PATH environment variable. they're the VIPs of the search path list π
--impureβ allow access to mutable paths and repositories. living dangerously, love that for you.--optionname value β set the Nix configuration option name to value. this overrides settings in the Nix configuration file (seenix.conf5).--repairβ fix corrupted or missing store paths by redownloading or rebuilding them. note that this is slow, because it requires computing a cryptographic hash of the contents ofeverypath in the closure of the build. also note the warning undernix-store --repair-path. it works, it's just not fast, ok? go make a snack while it runs π
Note β see man nix.conf for overriding configuration settings with command line flags.
β¨ Common Environment Variables β¨
Okay bestie, most Nix commands be like, yeah, I read these env vars, periodt. So hereβs the whole vibe. π
πΈ Configuration environment variables πΈ
These lilβ guys affect how Nix loads its config. The configuration file docs have the full tea, iykyk. βοΈ
NIX_CONF_DIRβ Overrides the system configuration directory. ποΈNIX_USER_CONF_FILESβ Overrides the user configuration file locations. πNIX_CONFIGβ Provides configuration settings inline. π
ποΈ Store setting environment variables ποΈ
NIX_IGNORE_SYMLINK_STOREβ So normally, the Nix store directory (typically/nix/store) is not allowed to contain any symlink components. This is to prevent βimpureβ builds. Builders sometimes βcanonicaliseβ paths by resolving all symlink components. Thus, builds on different machines (with/nix/storeresolving to different locations) could yield different results. This is generally not a problem, except when builds are deployed to machines where/nix/storeresolves differently. If you are sure that youβre not going to do that, you can setNIX_IGNORE_SYMLINK_STOREto1. π
Note that if youβre symlinking the Nix store so that you can put it on another file system than the root file system, on Linux youβre better off using bind mount points, e.g.,
$ mkdir /nix
$ mount -o bind /mnt/otherdisk/nix /nix
Consult the mount 8 manual page for details. π
NIX_STORE_DIRβ Overrides the location of the Nix store. On Unix, the default is/nix/store, set at compile time by thelibstore:store-dirbuild option. On Windows, there is no compile-time setting; the default is%PROGRAMDATA%\nix\store, determined at runtime using the%PROGRAMDATA%Known Folder. πͺ
See the Store Types chapter; each store has a store setting linking back to this as its default. π
NIX_LOG_DIRβ Overrides the location of the Nix log directory. On Unix, the default is/nix/var/log/nix, set at compile time by thelog-dirbuild option. On Windows, there is no compile-time setting; the default is%PROGRAMDATA%\nix\log, determined at runtime using the%PROGRAMDATA%Known Folder.
The Local Store, Local Daemon Store, and Experimental SSH Store with filesystem mounted have per-store settings that override this. πͺ
NIX_STATE_DIRβ Overrides the location of the Nix state directory. On Unix, the default is${localstatedir}/nix, wherelocalstatediris a compile-time build option defaulting to/nix/var. On Windows, there is no compile-time setting; the default is%PROGRAMDATA%\nix\state, determined at runtime using the%PROGRAMDATA%Known Folder.
The Local Store, Local Daemon Store, and Experimental SSH Store with filesystem mounted have per-store settings that override this. πͺ
NIX_DAEMON_SOCKET_PATHβ Overrides the path to the Unix domain socket used to communicate with the Nix daemon. Defaults todaemon-socket/socketwithin the state directory (seeNIX_STATE_DIR). π
See the Local Daemon Store documentation for details on how the socket path is resolved. π‘
TMPDIRβ Use the specified directory to store temporary files. In particular, this includes temporary build directories; these can take up substantial amounts of disk space. The default is/tmp. πΎNIX_REMOTEβ Overrides the store setting. π
π§ Nix language evaluator settings π§
NIX_SHOW_STATSβ If set to1, Nix will print some evaluation statistics, such as the number of values allocated. πNIX_COUNT_CALLSβ If set to1, Nix will print how often functions were called during Nix expression evaluation. This is useful for profiling your Nix expressions. πGC_INITIAL_HEAP_SIZEβ If Nix has been configured to use the Boehm garbage collector, this variable sets the initial size of the heap in bytes. It defaults to384 MiB. Setting it to a low value reduces memory consumption, but will increase runtime due to the overhead of garbage collection. β»οΈNIX_PATHβ A colon-separated list of search path entries used to resolve lookup paths. π§
This environment variable overrides the value of the nix-path configuration setting.
It can be extended using the -I option.
Example:
$ export NIX_PATH=/home/eelco/Dev:nixos-config=/etc/nixos
If NIX_PATH is set to an empty string, resolving search paths will always fail. π«
Example:
$ NIX_PATH= nix-instantiate --eval '<nixpkgs>'
error: file 'nixpkgs' was not found in the Nix search path (add it using $NIX_PATH or -I)
π User Directories π
Nix supports per-user configuration, state, and cache directories. The following environment variables override the locations for these directories: π
- user configuration directory (anchor:
user-conf-dir):NIX_CONFIG_HOME(anchor:env-NIXCONFIGHOME) π οΈ - user state directory:
NIX_STATE_HOME(anchor:env-NIXSTATEHOME) π - user cache directory:
NIX_CACHE_HOME(anchor:env-NIXCACHEHOME) ποΈ
When these are not set, the defaults depend on the platform: π
- On Unix, the XDG base directories:
$XDG_CONFIG_HOME/nix,$XDG_STATE_HOME/nix,$XDG_CACHE_HOME/nixπ§ - On Windows, the Windows Known Folders:
%APPDATA%\nix\config,%LOCALAPPDATA%\nix\state,%LOCALAPPDATA%\nix\cacheπͺ
For backwards compatibility, legacy Nix commands (e.g. nix-env, nix-channel) use dotfiles in $HOME instead of these directories unless use-xdg-base-directories is enabled. New Nix commands (experimental) use the proper directories by default. π΅
When use-xdg-base-directories is enabled, the configuration directory is resolved as: π
$NIX_CONFIG_HOME, if it is defined- Otherwise, the platform default (e.g.
$XDG_CONFIG_HOME/nixon Unix)
Likewise for the state and cache directories. β¨
π² Miscellaneous environment variables π²
IN_NIX_SHELLβ Indicator that tells if the current environment was set up bynix-shell. It can have the valuespureorimpure. π
π Appendix: OS-specific conventions π
This information is not Nix-specific, but is referenced above. So hereβs a lilβ bonus. π
π§ Unix: XDG Base Directories π§
The XDG Base Directory Specification defines standard locations for user-specific configuration, state, and cache files on Unix systems. πΊοΈ
The following environment variables are used:
XDG_CONFIG_HOME(anchor:env-XDGCONFIGHOME) (default~/.config) βοΈXDG_STATE_HOME(anchor:env-XDGSTATEHOME) (default~/.local/state) πXDG_CACHE_HOME(anchor:env-XDGCACHEHOME) (default~/.cache) ποΈXDG_CONFIG_DIRS(anchor:env-XDGCONFIGDIRS) (default/etc/xdg) β colon-separated list of additional configuration base directories, searched afterXDG_CONFIG_HOMEπ
πͺ Windows: Known Folders πͺ
On Windows, Known Folders provide standard locations for application data on Windows. πͺ
The relevant folders are:
%APPDATA%(anchor:env-APPDATA) β per-user roaming application data π%LOCALAPPDATA%(anchor:env-LOCALAPPDATA) β per-user local application data π%PROGRAMDATA%(anchor:env-PROGRAMDATA) β system-wide application data π
π Examples π
This operation is typically used to build store derivations produced by nix-instantiate: ποΈ
$ nix-store --realise $(nix-instantiate ./test.nix)
/nix/store/6gwmy5jcnwdlz6aqqhksz863f1l8xc2w-aterm-2.3.1
This is essentially what nix-build does. π―
To test whether a previously-built derivation is deterministic:
$ nix-build '<nixpkgs>' --attr hello --check -K
Use nix-store --read-log to show the stderr and stdout of a build:
$ nix-store --read-log $(nix-instantiate ./test.nix)
And thatβs the whole vibe, bestie! This was nix-store --realise(1), no cap. Stay slay, keep your store pure, and donβt forget to read the docs. πβ¨π
π¦ where this page comes from
- fedora 44: nix-legacy 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