NIX-STORE-LOAD-DB(1)

✨ nix-store --load-db(1) ✨

okay so this one lives in the General Commands Manual, bestie πŸ’– pull up a chair, we're importing a whole database and it's gonna be iconic.


πŸŽ€ NAME πŸŽ€

nix-store --load-db β€” import Nix database πŸ—„οΈβœ¨

🌸 SYNOPSIS 🌸

nix-store --load-db

πŸ¦‹ DESCRIPTION πŸ¦‹

So the --load-db operation reads a dump of the Nix database β€” one that was made earlier by --dump-db β€” straight from standard input, and loads it into the Nix database. That's it. That's the whole vibe. Stdin in, database updated, slay. πŸ’…

πŸ‘‘ OPTIONS πŸ‘‘

Real talk: the options below are allowed for all nix-store operations, but ngl they might not always actually do anything depending on what you're running. iykyk. πŸ™ˆ

  • --add-root path β€” this one makes the result of a realisation (so like, --realise and --force-realise) get registered as a root of the garbage collector. ✨ What happens is path gets created as a symlink pointing at the resulting store path. On top of that, a uniquely-named symlink to path gets created over in /nix/var/nix/gcroots/auto/. For example, bestie:
$ 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

So the way this works is: when /home/eelco/bla/result gets removed, the GC root sitting in the auto directory turns into a dangling symlink and the collector will just ignore it. 🫢

⚠️ WARNING ⚠️ okay this part matters, no cap: it is not possible to move or rename GC roots, because the symlink in the auto directory will still be pointing at the old location. so like… don't try it. πŸ’€

Also, and this is kinda cute: if there are multiple results, then multiple symlinks get created β€” they're just sequentially numbered past the first one, like foo, foo-2, foo-3, and so on. 🌈⭐


and we're not done yet β€” more of this page is coming πŸ”₯

πŸ’… Common Options πŸ’…

okay bestie so like almost every Nix command speaks this same little dialect of flags, and once you learn it you're basically fluent, no cap:

  • --help β€” dumps a lil summary of the command syntax at you and then dips. 🫢
  • --version β€” prints the Nix version number on standard output and exits. that's it, that's the whole job. ✨
  • --verbose / -v β€” cranks the level of verbosity of diagnostic messages printed on standard error. and listen, this part MATTERS: for each Nix operation, whatever lands on standard output is well-defined; all the diagnostic info goes to standard error, never to standard output. okay queen, keep your streams separate πŸ’…

you can stack this option over and over again. currently these verbosity levels exist:

  • 0 β€œErrors only” β€” only print messages explaining why the Nix invocation failed. the bare minimum, lowkey.
  • 1 β€œInformational” β€” print useful messages about what Nix is doing. this is the default, so this is where you live rn.
  • 2 β€œTalkative” β€” print more informational messages.
  • 3 β€œChatty” β€” print even more informational messages. she's yapping and we love her.
  • 4 β€œDebug” β€” print debug information.
  • 5 β€œVomit” β€” print vast amounts of debug information. it's giving unhinged and honestly? iconic πŸ’€
  • --quiet β€” decreases the level of verbosity of diagnostic messages printed on standard error. it's literally the inverse option to -v / --verbose. πŸ™ˆ

this one can also be given repeatedly. see the verbosity levels list right above, it's the same ladder just going the other way.

  • --log-format format β€” flips up what the log output actually looks like, with format being one of these:
    • raw β€” 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 don't get too attached to that shape, bestie.
  • bar β€” only display a progress bar during the builds. minimalism queen ✨
  • bar-with-logs β€” display the raw logs, with the progress bar at the bottom. best of both worlds fr fr.
  • --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 nothing's actually lost πŸ’–
  • --max-jobs / -j number β€” sets the maximum number of build jobs that Nix will perform in parallel to the specified number. say auto and it'll use the number of CPUs in the system. the default comes from the max-jobs configuration setting, which itself defaults to 1. a higher value is useful on SMP systems or to exploit I/O latency. ✨

setting it to 0 disallows building on the local machine, which is useful when you want builds to happen only on remote builders. main character energy: outsourcing the labour 😌

  • --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 maximum 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 that the builder should use all available CPU cores in the system. go off, use everything πŸ”₯
  • --max-silent-time β€” sets the maximum number of seconds that a builder can go without producing any data on standard output or standard error. the default is specified by the max-silent-time configuration setting. 0 means no time-out. silence is golden but also suspicious πŸ‘€
  • --timeout β€” sets the maximum number of seconds that a builder can run. the default is specified by the timeout configuration setting. 0 means no timeout. give her a curfew or don't, your call ⏰
  • --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). it's the "we don't stop, we keep it moving" flag πŸ’ͺ
  • --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. so you get to go poke at the crime scene afterward πŸ”
  • --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 in which 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, one little hiccup on the network should not send you into a three-hour source compile, bestie 😭

  • --readonly-mode β€” when this option is used, no attempt is made to open the Nix database. most Nix operations do need database access, so those operations will fail. look but don't touch πŸ‘‘πŸ’€
  • --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. the shells are dramatic like that πŸ’…)

  • --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 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. way less escaping drama, obsessed 🌸
  • --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 bestie, 3 is the fourth element β€” zero-indexing is just how she rolls 😌

  • --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. (yes, "contain" β€” we're quoting her verbatim, she's doing her best πŸŽ€)

  • -I / --include path β€” add an entry to the list of search paths used to resolve lookup paths. this option may 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. she jumps the queue and honestly she's earned it πŸ‘‘

  • --impure β€” allow access to mutable paths and repositories. wild child behaviour, proceed with intention πŸ¦‹
  • --option name value β€” set the Nix configuration option name to value. this overrides settings in the Nix configuration file (see nix.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 of every path in the closure of the build. also note the warning under nix-store --repair-path. like, she will fix it, but she will take her sweet time doing it 😭
Note ✨ see man nix.conf for overriding configuration settings with command line flags.

✨ Common Environment Variables ✨

okay bestie, real talk: most Nix commands read the env vars down below whenever they fire up. so lock in. πŸ’–

πŸ”§ Configuration environment variables

These ones decide how Nix loads its config. For the full deets, go peek at the configuration file documentation.

  • NIX_CONF_DIR β€” overrides the system configuration directory. πŸ—‚οΈ
  • NIX_USER_CONF_FILES β€” overrides where the user configuration files live.
  • NIX_CONFIG β€” lets you drop configuration settings in inline, no file needed.

🏬 Store setting environment variables

  • NIX_IGNORE_SYMLINK_STORE β€” so normally the Nix store directory (usually /nix/store) is not allowed to contain any symlink components. Why? to stop "impure" builds, periodt. Builders sometimes "canonicalise" paths by resolving all symlink components, so builds on different machines (where /nix/store resolves to different places) could spit out different results. Usually that's fine β€” except when you deploy builds to machines where /nix/store resolves somewhere else. If you're sure you're not gonna do that, you can set NIX_IGNORE_SYMLINK_STORE to 1. 😌

Heads up tho: if you're symlinking the Nix store just to park it on a different file system than root, on Linux you're lowkey better off using bind mount points, like:

$ mkdir /nix
$ mount -o bind /mnt/otherdisk/nix /nix
  • Consult the mount 8 manual page for the details. πŸ“–
  • 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, figured out at runtime using the %PROGRAMDATA% Known Folder. πŸͺŸ

See the Store Types chapter β€” every store has a store setting linking back to this as its default.

  • NIX_LOG_DIR β€” overrides where the Nix log directory lives. 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; default is %PROGRAMDATA%\nix\log, determined at runtime via the %PROGRAMDATA% Known Folder.

The Local Store, Local Daemon Store, and Experimental SSH Store with filesystem mounted have per-store settings that override this one.

  • 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; default is %PROGRAMDATA%\nix\state, determined at runtime using the %PROGRAMDATA% Known Folder.

Same trio as above β€” Local Store, Local Daemon Store, and Experimental SSH Store with filesystem mounted β€” have per-store settings that override it.

  • NIX_DAEMON_SOCKET_PATH β€” overrides the path to the Unix domain socket used to talk to the Nix daemon. Defaults to daemon-socket/socket inside the state directory (see NIX_STATE_DIR). πŸ”Œ

See the Local Daemon Store documentation for how the socket path actually gets resolved. iykyk.

  • TMPDIR β€” use this directory to store temporary files. That includes temporary build directories, which can eat up substantial amounts of disk space btw. Default is /tmp. πŸ—‘οΈ
  • NIX_REMOTE β€” overrides the store setting.

🧠 Nix language evaluator settings

  • NIX_SHOW_STATS β€” set it to 1 and Nix prints some evaluation statistics, like how many values got allocated. πŸ“Š
  • NIX_COUNT_CALLS β€” set it to 1 and Nix prints how often functions were called during Nix expression evaluation. Super useful for profiling your Nix expressions. πŸ”
  • GC_INITIAL_HEAP_SIZE β€” if Nix was configured to use the Boehm garbage collector, this sets the initial size of the heap in bytes. Defaults to 384 MiB. Setting it low reduces memory consumption, but makes runtime go up because of garbage collection overhead. The eternal tradeoff, bestie. βš–οΈ
  • 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 does per-user configuration, state, and cache directories. These env vars override where those live:

  • [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 they're 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 (like 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 resolves like this:

  1. $NIX_CONFIG_HOME, if it is defined
  2. Otherwise, the platform default (e.g. $XDG_CONFIG_HOME/nix on Unix)

And likewise for the state and cache directories. 🫢

🎲 Miscellaneous environment variables

  • IN_NIX_SHELL β€” a little indicator that tells you if the current environment was set up by nix-shell. It can have the values pure or impure.

πŸ“Ž Appendix: OS-specific conventions

Just so you know, this info is not Nix-specific β€” it's referenced above, that's all. πŸ’…

🐧 Unix: XDG Base Directories

The XDG Base Directory Specification defines standard locations for user-specific configuration, state, and cache files on Unix systems.

Here are the env vars it uses:

  • [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 extra configuration base directories, searched after XDG_CONFIG_HOME

πŸͺŸ Windows: Known Folders

On Windows, Known Folders give you standard locations for application data.

The relevant ones 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 a wrap on this one, bestie πŸŽ€ you just made it through the whole nix-store --load-db(1) page β€” genuinely iconic behavior, no cap πŸ‘‘ the page footer is just the humble nix-store --load-db(1) signature with its source/version and date chilling at the bottom, so consider this your cute lil sign-off instead. go load some databases. slay. πŸ’–βœ¨

πŸ“¦ where this page comes from