NIX-STORE-DUMP-DB(1)

✨ nix-store --dump-db(1) β€” General Commands Manual ✨

okay bestie, buckle up, we're reading the manual for nix-store --dump-db πŸ’– (yes that's the whole name, section 1, general commands, iconic behavior)


🌸 NAME 🌸

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


πŸŽ€ SYNOPSIS πŸŽ€

nix-store --dump-db [paths…]

πŸ¦‹ DESCRIPTION πŸ¦‹

so the operation --dump-db writes a dump of the Nix database to standard output. that's it, that's the whole vibe. πŸ’Ύ

and then you can load that dump into an empty Nix store using --load-db. which is lowkey so useful for making backups, and also for when you're migrating to different database schemas. it's giving "i archived my whole personality" fr fr 🫢

By default, --dump-db will dump the entire Nix database. no filter, no crumbs, the whole thing. πŸ‘‘

But when one or more store paths is passed, only the subset of the Nix database for those store paths is dumped. and here's the part you cannot skip, bestie: as with --export, the user is responsible for passing all the store paths for a closure. nobody's gonna do it for you. 😭 See --export for an example.


πŸ’… OPTIONS πŸ’…

The following options are allowed for all nix-store operations, but may not always have an effect. (so like, they're always invited to the party, but they don't always show up πŸ’€)

  • --add-root path β€” 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. In addition, 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. no cap, it just stops counting. πŸ™ˆ

⚠️ 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. so don't try it. the auto symlink does not get the memo, ever. πŸ’€

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). literally just counting up, slay. πŸ”’βœ¨


(to be continued bestie, there's more coming πŸ’–)

✨ Common Options ✨

Okay so most Nix commands accept these command-line options, and you're gonna wanna know them because they're literally everywhere πŸ’…

  • --help β€” prints out a summary of the command syntax and then dips out. That's it, that's the whole thing 🫢
  • --version β€” prints out the Nix version number on standard output and exits. Iconic, brief, no notes.
  • --verbose, -v β€” cranks up the level of verbosity of diagnostic messages printed on standard error. And bestie, listen: for each Nix operation, the info printed on standard output is well-defined, and any diagnostic info goes on standard error, never on standard output. That distinction matters, ok? πŸ’–

This option may be specified repeatedly (stack it up, it compounds πŸŽ€). Currently the following verbosity levels exist:

  • 0 β€œErrors only” β€” only print messages explaining why the Nix invocation failed. Bare minimum mode 😭
  • 1 β€œInformational” β€” print useful messages about what Nix is doing. This is the 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. The name is not a joke πŸ’€
  • --quiet β€” decreases the level of verbosity of diagnostic messages printed on standard error. It's the inverse option to -v / --verbose. This option may be specified repeatedly too, and it uses those same verbosity levels from the list right above ⬆️
  • *--log-format *format β€” this one changes the output of the log format, and format has to be 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 you dare hard-depend on it, bestie πŸ™ˆ
  • bar β€” only displays a progress bar during the builds.
  • bar-with-logs β€” displays 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 gets echoed to the Nix command's standard error. This option suppresses that. But heads up: the builder's standard output and error are always written to a log file in prefix/nix/var/log/nix regardless πŸ“
  • *--max-jobs, -j *number β€” sets the max number of build jobs Nix will do in parallel to the specified number. You can pass auto to use the number of CPUs on 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 exactly what you want when you only want builds happening on remote builders πŸ‘‘
  • --cores β€” sets the value of the NIX_BUILD_CORES environment variable when builders get invoked. Builders can use that variable however they want to control max 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 that's set, or 1 otherwise. And the value 0 means the builder should use all available CPU cores in the system πŸ”₯
  • --max-silent-time β€” sets the max number of seconds a builder can go without producing any data on standard output or standard error. The default comes from the max-silent-time configuration setting. 0 means no time-out. Zzz-proof πŸ’€
  • --timeout β€” sets the max number of seconds a builder can run. The default comes from the timeout configuration setting. 0 means no timeout.
  • --keep-going, -k β€” keep going in case of failed builds, to the greatest extent possible. So 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 the case of parallel or distributed builds. Resilient queen behaviour πŸ’…
  • --keep-failed, -K β€” says that in case of a build failure, the temporary directory (usually in /tmp) where the build takes place should not be deleted. The path of the build directory gets printed as an informational message, so you can go investigate πŸ•΅οΈ
  • --fallback β€” whenever Nix tries to build a derivation for which substitutes are known for each output path, but realising the output paths through the substitutes fails, it falls back on building the derivation.

The most common scenario where this saves you: you've got registered substitutes so you can do binary distribution from, like, a network repository. If the repository is down, realising the derivation will fail β€” but with this option, Nix will build the derivation instead. So installation from binaries falls back on installation from source πŸ¦‹

This option is not the default, because it's generally not desirable for a transient failure in obtaining the substitutes to lead to a full build from source with all the related resource consumption. Like, that's a whole lot, bestie 😭

  • --readonly-mode β€” when this is used, no attempt is made to open the Nix database. Most Nix operations do need database access, so those operations will fail. Read-only and proud, but also maybe lonely πŸ₯²
  • *--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). So if the evaluator encounters a function with an argument named name, it will call it with 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.) Sneaky little quoting rule, don't get caught slippin' πŸ™ˆ

  • *--arg-from-file *name path β€” pass the contents of file path as the argument name to Nix functions. Chef's kiss, no quoting drama πŸŽ€
  • *--arg-from-stdin *name β€” pass the contents of stdin as the argument name to Nix functions.
  • *--argstr *name value β€” this one's like --arg, except the value is not a Nix expression, it's a string. So instead of --arg system \"i686-linux\" (those outer quotes are just to keep the shell happy), you can just say --argstr system i686-linux. Way less escaping, way more slay ✨
  • --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, fourth β€” indices start at zero, that's the vibe 🌸

  • *--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 a shell that contains the built packages ready for use, give your expression to the nix-shell --packages convenience flag instead. Different goal, different flag, don't mix 'em up 😌

  • -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 πŸ“š).

Paths added through -I take precedence over the nix-path configuration setting and the NIX_PATH environment variable. Precedence queen, she wins every time πŸ‘‘

  • --impure β€” allow access to mutable paths and repositories. Living dangerously, love that for you 😏
  • *--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. Heads up though: 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. Go in with snacks, this one takes a minute πŸ“
πŸ“ Note: See man nix.conf for overriding configuration settings with command line flags.

🌈 COMMON ENVIRONMENT VARIABLES 🌈

okay bestie, this part is the ✨deep lore✨ β€” it's all the env vars that most Nix commands actually read. Set them, export them, love them. πŸ’…


πŸŽ€ Configuration environment variables

These ones decide how Nix loads up its configuration. The full tea is in the configuration file documentation, but here's the short version:

  • NIX_CONF_DIR β€” overrides the system configuration directory. πŸ—‚οΈ
  • NIX_USER_CONF_FILES β€” overrides the user configuration file locations.
  • NIX_CONFIG β€” lets you hand Nix configuration settings inline, right there in the variable. iconic, honestly. ✨

πŸ›οΈ Store setting environment variables

  • NIX_IGNORE_SYMLINK_STORE β€” okay so normally the Nix store directory (typically /nix/store) is not allowed to contain any symlink components, and that's on purpose: it's to prevent "impure" builds. see, builders sometimes "canonicalise" paths by resolving every symlink component, so builds on different machines (where /nix/store resolves to different places) could totally give you different results. usually that's fine β€” except when builds get deployed to machines where /nix/store resolves differently. if you're sure you're not gonna do that, you can set NIX_IGNORE_SYMLINK_STORE to 1.
also, if you're symlinking the Nix store so you can park it on another filesystem than the root filesystem, on Linux you're better off using bind mount points, like:
$ mkdir /nix
$ mount -o bind /mnt/otherdisk/nix /nix

Consult the mount(8) manual page for details. 🫢

  • NIX_STORE_DIR β€” overrides where the Nix store lives. 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 at all; the default is %PROGRAMDATA%\nix\store, figured out at runtime using the %PROGRAMDATA% Known Folder.

peek the Store Types chapter β€” every store has a store setting that links 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; the 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 all have per-store settings that override this. πŸ‘‘

  • NIX_STATE_DIR β€” overrides where the Nix state directory lives. 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.

Same deal: the 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).

The Local Daemon Store documentation has the details on how the socket path gets resolved. πŸ”Œ

  • TMPDIR β€” use this directory to stash temporary files. yes, that includes temporary build directories, and yes, those can eat a substantial amount of disk space. πŸ’€ The default is /tmp.
  • NIX_REMOTE β€” overrides the store setting.

🧠 Nix language evaluator settings

  • NIX_SHOW_STATS β€” if you set it to 1, Nix prints some evaluation statistics, like how many values got allocated. πŸ“Š
  • NIX_COUNT_CALLS β€” if you set it to 1, 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 variable sets the initial size of the heap, in bytes. it defaults to 384 MiB. setting it low reduces memory consumption, but it'll increase runtime because of garbage collection overhead. tradeoffs, 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.

You can extend it with 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 keeps per-user configuration, state, and cache directories, and these env vars override where they live:

  • user configuration directory: NIX_CONFIG_HOME
  • user state directory: NIX_STATE_HOME
  • user cache directory: NIX_CACHE_HOME

When those aren't set, the defaults depend on your 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 resolves like this:

  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. ✨


🎲 Miscellaneous environment variables

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

πŸ“Ž APPENDIX: OS-SPECIFIC CONVENTIONS πŸ“Ž

This info isn't Nix-specific at all, but it's referenced up above, so here it is. 🫢

🐧 Unix: XDG Base Directories

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

These are the environment variables in play:

  • XDG_CONFIG_HOME (default ~/.config)
  • XDG_STATE_HOME (default ~/.local/state)
  • XDG_CACHE_HOME (default ~/.cache)
  • XDG_CONFIG_DIRS (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 the standard locations for application data.

The relevant folders are:

  • %APPDATA% β€” per-user roaming application data
  • %LOCALAPPDATA% β€” per-user local application data
  • %PROGRAMDATA% β€” system-wide application data

and that's the whole page, bestie!! πŸŽ€ you just read the entire nix-store --dump-db(1) manual page β€” every last env var, every platform quirk, no cap. slay. πŸ’–βœ¨ go forth and dump some databases, you icon. πŸ‘‘πŸ¦‹πŸ’œ

πŸ“¦ where this page comes from