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-rootpath β causes the result of a realisation (--realiseand--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, andformathas to be one of these:rawβ 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 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 inprefix/nix/var/log/nixregardless π- *
--max-jobs,-j*numberβ sets the max number of build jobs Nix will do in parallel to the specified number. You can passautoto use the number of CPUs on the system. The default comes from themax-jobsconfiguration setting, which itself defaults to1. A higher value is useful on SMP systems, or to exploit I/O latency. Setting it to0disallows 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 theNIX_BUILD_CORESenvironment variable when builders get invoked. Builders can use that variable however they want to control max 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, or1otherwise. And the value0means 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 themax-silent-timeconfiguration setting.0means no time-out. Zzz-proof π€--timeoutβ sets the max number of seconds a builder can run. The default comes from thetimeoutconfiguration setting.0means 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*namevalueβ 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). 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*namepathβ pass the contents of filepathas the argumentnameto Nix functions. Chef's kiss, no quoting drama π - *
--arg-from-stdin*nameβ pass the contents of stdin as the argumentnameto Nix functions. - *
--argstr*namevalueβ this one's like--arg, except thevalueis 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,-AattrPathβ select an attribute from the top-level Nix expression being evaluated. (nix-env,nix-instantiate,nix-buildandnix-shell*only.) The attribute path *attrPathis a sequence of attribute names separated by dots. For instance, given a top-level Nix expressione, 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, 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 (.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 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*namevalueβ set the Nix configuration optionnametovalue. This overrides settings in the Nix configuration file (seenix.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 undernix-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/storeresolves to different places) could totally give you different results. usually that's fine β except when builds get deployed to machines where/nix/storeresolves differently. if you're sure you're not gonna do that, you can setNIX_IGNORE_SYMLINK_STOREto1.
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 thelibstore:store-dirbuild 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 thelog-dirbuild 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, 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.
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 todaemon-socket/socketinside the state directory (seeNIX_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 to1, Nix prints some evaluation statistics, like how many values got allocated. πNIX_COUNT_CALLSβ if you set it to1, 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:
$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β an indicator that tells you whether the current environment was set up bynix-shell. It can have the valuespureorimpure. π
π 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 afterXDG_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
- 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