NIX-STORE-RESTORE(1)
๐ธ NAME ๐ธ
okay bestie, this is the manual for nix-store --restore(1) from the General Commands Manual. Itโs giving โextract a Nix archiveโ energy. ๐
nix-store --restoreโ extract a Nix archive โจ
๐ฆ SYNOPSIS ๐ฆ
nix-store --restore path
๐ DESCRIPTION ๐
So basically, the operation --restore unpacks a Nix Archive (NAR) into path, and bestie, path must not already exist โ no cap. The archive gets read from standard input. ๐
๐ OPTIONS ๐
The following options are allowed for all nix-store operations, but lowkey they may not always have an effect. ๐
--add-rootpath โ this 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. On top of that, 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 likeโฆ most Nix commands? They all speak the same love language, and it's these flags. bestie, if you learn these once, you basically know how to talk to like every Nix tool ever. ๐
--helpโ prints out a lil summary of the command syntax and then dips (exits). iconic behavior honestly.--versionโ prints the Nix version number on standard output and exits. that's it. that's the whole vibe. โจ--verbose,-vโ turns up the volume on diagnostic messages printed to standard error. ๐ธ real talk: for each Nix operation, the info printed on standard output is well-defined, and any diagnostic info goes to standard error, never to standard output. no cap. you can pass this option over and over again (it stacks!). currently these verbosity levels exist:- 0 โErrors onlyโ โ only print messages explaining why the Nix invocation failed. ๐
- 1 โInformationalโ โ print useful messages about what Nix is doing. this is the default, so it's the main character by default.
- 2 โTalkativeโ โ print more informational messages.
- 3 โChattyโ โ print even more informational messages.
- 4 โDebugโ โ print debug information.
- 5 โVomitโ โ print vast amounts of debug information. literally. it's giving firehose. ๐ญ
--quietโ turns the volume down on diagnostic messages printed to standard error. it's the inverse option to-v/--verbose. you can pass it repeatedly too, so stack away. see the previous verbosity levels list for the whole ladder. ๐ซถ--log-formatformat โ changes the output of the log format, where format is one of:rawโ this is the raw format, 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 build your whole personality on parsing it, k?
barโ only display a progress bar during the builds. so satisfying.bar-with-logsโ display the raw logs, with the progress bar at the bottom. best of both worlds tbh. ๐
--no-build-output,-Qโ by default, output written by builders to standard output and standard error is echoed to the Nix command's standard error. this option suppresses that behaviour. heads up tho: the builder's standard output and error are always written to a log file inprefix/nix/var/log/nix. so it's never gone, just not shouted at you. ๐--max-jobs,-jnumber โ sets the max number of build jobs Nix will do in parallel to number. you can specifyautoto use the number of CPUs in the system. the default is specified by themax-jobsconfiguration setting, which itself defaults to1. a higher value is useful on SMP systems or to exploit I/O latency. ๐ฅ and setting it to0disallows building on the local machine โ which is useful when you want builds to happen only on remote builders. like, stay in your lane, local machine.--coresโ sets the value of theNIX_BUILD_CORESenvironment variable in the invocation of builders. builders can use this variable at their discretion to control the max 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 set, or1otherwise. the value0means the builder should use all available CPU cores in the system. go off, bestie, use every single core. ๐ค--max-silent-timeโ sets the max number of seconds that a builder can go without producing any data on standard output or standard error. (imagine going quiet for that longโฆ couldn't be me.) the default is specified by themax-silent-timeconfiguration setting.0means no time-out.--timeoutโ sets the max number of seconds that a builder can run. the default is specified by thetimeoutconfiguration setting.0means no timeout. periodt.--keep-going,-kโ keep going in case of failed builds, to the greatest extent possible. that is, 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), possibly killing builds in progress (in case of parallel or distributed builds). so like, dramatic much? ๐ซ--keep-failed,-Kโ specifies that in case of a build failure, the temporary directory (usually in/tmp) in which the build takes place should not be deleted. the path of the build directory is printed as an informational message. leaving the crime scene intact for forensics, love that for us. ๐--fallbackโ whenever Nix attempts to build a derivation for which substitutes are known for each output path, but realising the output paths through the substitutes fails, fall back on building the derivation.
the most common scenario where this is useful is when we have registered substitutes in order to perform binary distribution from, say, a network repository. if the repository is down, the realisation of the derivation will fail. when this option is specified, Nix will build the derivation instead. thus, installation from binaries falls back on installation from source. ๐ธ
this option is not the default since it is generally not desirable for a transient failure in obtaining the substitutes to lead to a full build from source (with the related consumption of resources). like yeah bestie, one tiny network hiccup should not spawn a whole compile, that's giving chaos.
--readonly-modeโ when this option is used, no attempt is made to open the Nix database. heads up: most Nix operations do need database access, so those operations will fail. ๐ read-only truly means read-only.--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 for which 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). that is, if the evaluator encounters a function with an argument named name, it will call it with value 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 will be called automatically using the value builtins.currentSystem for the system argument. you can override this 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.) so sorry to the quotes, they really do have to be escaped. ๐
--arg-from-filename path โ pass the contents of file path as the argument name to Nix functions. feeding it straight from a file, fancy. ๐--arg-from-stdinname โ pass the contents of stdin as the argument name to Nix functions. piping it in like a little straw. ๐ฅค--argstrname value โ this option is like--arg, only the value is not a Nix expression but a string. so instead of--arg system \"i686-linux\"(the outer quotes are to keep the shell happy) you can say--argstr system i686-linux. the shell stays happy, you stay happy, everybody wins. ๐ฆ--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, 3 is the fourth โ zero-indexed moment. indexing is literally so real.) โญ
--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 to get a shell which contain the built packages ready for use, give your expression to the nix-shell --packages convenience flag instead. ok that's the distinction, write it down bestie. ๐
-I,--includepath โ add an entry to the list of search paths used to resolve lookup paths. this option may be given multiple times (collect them all ๐).
paths added through -I take precedence over the nix-path configuration setting and the NIX_PATH environment variable. so they're the VIPs at the front of the line. ๐
--impureโ allow access to mutable paths and repositories. living dangerously, we love a rebel. ๐--optionname value โ set the Nix configuration option name to value. this overrides settings in the Nix configuration file (seenix.conf5). command line > config file, always.--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 of every path in the closure of the build. ๐ญ also note the warning undernix-store --repair-path. so like, hydrate first, this one takes a minute. ๐
๐ Note โ see man nix.conf for overriding configuration settings with command line flags.
๐ Common Environment Variables ๐
okay bestie, hear me out โ most Nix commands read these environment variables, like literally all the popular ones. So if something's acting weird, this is your vibe check. ๐
๐ Configuration environment variables ๐
These cuties control how Nix loads its configuration. The full story lives in the configuration file documentation if you wanna go deeper, but here's the tea:
NIX_CONF_DIRโ overrides the system configuration directory. slay.NIX_USER_CONF_FILESโ overrides where the user configuration files live. โจNIX_CONFIGโ lets you hand Nix configuration settings inline, right there in the env. iconic.
๐๏ธ Store setting environment variables ๐๏ธ
NIX_IGNORE_SYMLINK_STOREโ okay so normally the Nix store directory (usually/nix/store) is not allowed to contain any symlink components. Why? To prevent "impure" builds, periodt. Here's the thing: builders sometimes "canonicalise" paths by resolving all symlink components, so builds on different machines (where/nix/storeresolves to different places) could give you different results. Usually that's not a problem โ except when builds get deployed to machines where/nix/storeresolves differently. If you're 100% sure you're not gonna do that, you can setNIX_IGNORE_SYMLINK_STOREto1.
pro tip bestie: if you're symlinking the Nix store just to stick it on another file system than the root file system, on Linux you're way better off using bind mount points, like this ๐
$ mkdir /nix
$ mount -o bind /mnt/otherdisk/nix /nix
Consult the mount 8 manual page for the details, ok? ๐ซถ
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's 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, again 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 all 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, no compile-time setting; the default is%PROGRAMDATA%\nix\state, determined at runtime using the%PROGRAMDATA%Known Folder.
And yeah โ the Local Store, Local Daemon Store, and Experimental SSH Store with filesystem mounted have per-store settings that override this too. same energy.
NIX_DAEMON_SOCKET_PATHโ overrides the path to the Unix domain socket used to talk to the Nix daemon. Defaults todaemon-socket/socketwithin the state directory (peepNIX_STATE_DIR). See the Local Daemon Store documentation for the full deets on how the socket path gets resolved.TMPDIRโ use this directory to store temporary files. Specifically this includes temporary build directories, which can eat up a substantial amount of disk space, so like... be aware. The default is/tmp. ๐NIX_REMOTEโ overrides the store setting. short and sweet.
๐ง Nix language evaluator settings ๐ง
NIX_SHOW_STATSโ if set to1, Nix prints some evaluation statistics, like the number of values allocated. numbers girlies rise. ๐NIX_COUNT_CALLSโ if set to1, Nix prints how often functions were called during Nix expression evaluation. super useful for profiling your Nix expressions, fr fr. ๐ฅGC_INITIAL_HEAP_SIZEโ if Nix was configured to use the Boehm garbage collector, this variable sets the initial size of the heap in bytes. Defaults to384 MiB. Setting it low reduces memory consumption, but bestie it will increase runtime because of the overhead of garbage collection. trade-offs, always.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. You can also extend it using the -I option. ๐ซ
Example:
$ export NIX_PATH=/home/eelco/Dev:nixos-config=/etc/nixos
heads up: if NIX_PATH is set to an empty string, resolving search paths will always fail. like, every single time.
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:
[user configuration directory]{#user-conf-dir}:[NIX_CONFIG_HOME]{#env-NIXCONFIGHOME}- user state directory:
[NIX_STATE_HOME]{#env-NIXSTATEHOME} - user cache directory:
[NIX_CACHE_HOME]{#env-NIXCACHEHOME}
When these aren't 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 (iykyk), 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. glow up. โจ
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. same rules, different folders. ๐ฆ
๐ฒ Miscellaneous environment variables ๐ฒ
IN_NIX_SHELLโ an indicator that tells you if the current environment was set up bynix-shell. It can have the valuespureorimpure. cute lil label.
๐ Appendix: OS-specific conventions ๐
Just so we're clear: this info is not Nix-specific, but it's referenced above, so we're including it. full transparency. ๐
๐ง 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]{#env-XDGCONFIGHOME}(default~/.config)[XDG_STATE_HOME]{#env-XDGSTATEHOME}(default~/.local/state)[XDG_CACHE_HOME]{#env-XDGCACHEHOME}(default~/.cache)[XDG_CONFIG_DIRS]{#env-XDGCONFIGDIRS}(default/etc/xdg) โ a 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.
The relevant folders are:
[%APPDATA%]{#env-APPDATA}โ per-user roaming application data[%LOCALAPPDATA%]{#env-LOCALAPPDATA}โ per-user local application data[%PROGRAMDATA%]{#env-PROGRAMDATA}โ system-wide application data
and that's the whole page, bestie!! ๐ you made it to the end, so proud. this page is nix-store --restore(1) โ source is the Nix manual, and you're reading part three of three. go off and restore some vibes. ๐
๐๐ฎ
๐ฆ 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