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-root path โ€” this causes the result of a realisation (--realise and --force-realise) to be registered as a root of the garbage collector. path will be created as a symlink to the resulting store path. On top of that, a uniquely named symlink to path will 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-format format โ€” changes the output of the log format, where format is one of:
    • raw โ€” this is the raw format, as outputted by nix-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 in prefix/nix/var/log/nix. so it's never gone, just not shouted at you. ๐Ÿ’œ
  • --max-jobs, -j number โ€” sets the max number of build jobs Nix will do in parallel to number. you can specify auto to use the number of CPUs in the system. the default is specified by the max-jobs configuration setting, which itself defaults to 1. a higher value is useful on SMP systems or to exploit I/O latency. ๐Ÿ”ฅ and setting it to 0 disallows 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 the NIX_BUILD_CORES environment 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 attribute enableParallelBuilding is set to true, the builder passes the -jN flag to GNU Make. it defaults to the value of the cores configuration setting, if set, or 1 otherwise. the value 0 means 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 the max-silent-time configuration setting. 0 means no time-out.
  • --timeout โ€” sets the max number of seconds that a builder can run. the default is specified by the timeout configuration setting. 0 means 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.
  • --arg name value โ€” this option is accepted by nix-env, nix-instantiate, nix-shell and nix-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-file name path โ€” pass the contents of file path as the argument name to Nix functions. feeding it straight from a file, fancy. ๐ŸŽ€
  • --arg-from-stdin name โ€” pass the contents of stdin as the argument name to Nix functions. piping it in like a little straw. ๐Ÿฅค
  • --argstr name 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, -A attrPath โ€” select an attribute from the top-level Nix expression being evaluated. (nix-env, nix-instantiate, nix-build and nix-shell only.) the attribute path attrPath is a sequence of attribute names separated by dots. for instance, given a top-level Nix expression e, the attribute path xorg.xorgserver would cause the expression e.xorg.xorgserver to be used. see nix-env --install for 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-store store-url โ€” the URL to the Nix store to use for evaluation, i.e. where to store derivations (.drv files) 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-build and nix-shell only.)

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, --include path โ€” 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. ๐Ÿ˜
  • --option name value โ€” set the Nix configuration option name to value. this overrides settings in the Nix configuration file (see nix.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 under nix-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/store resolves to different places) could give you different results. Usually that's not a problem โ€” except when builds get deployed to machines where /nix/store resolves differently. If you're 100% sure you're not gonna do that, you can set NIX_IGNORE_SYMLINK_STORE to 1.
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 the libstore:store-dir build 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 the log-dir build 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, where localstatedir is 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 to daemon-socket/socket within the state directory (peep NIX_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 to 1, Nix prints some evaluation statistics, like the number of values allocated. numbers girlies rise. ๐Ÿ“Š
  • NIX_COUNT_CALLS โ€” if set to 1, 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 to 384 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:

  1. $NIX_CONFIG_HOME, if it is defined
  2. Otherwise, the platform default (e.g. $XDG_CONFIG_HOME/nix on 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 by nix-shell. It can have the values pure or impure. 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 after XDG_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