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-rootpath β this one makes the result of a realisation (so like,--realiseand--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-formatformat β flips up what the log output actually looks like, with format being 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 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 inprefix/nix/var/log/nix, so nothing's actually lost π--max-jobs/-jnumber β sets the maximum number of build jobs that Nix will perform in parallel to the specified number. sayautoand it'll use the number of CPUs in 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 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 theNIX_BUILD_CORESenvironment 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 attributeenableParallelBuildingis set totrue, the builder passes the-jNflag to GNU Make. it defaults to the value of thecoresconfiguration setting, if set, or1otherwise. the value0means 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 themax-silent-timeconfiguration setting.0means 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 thetimeoutconfiguration setting.0means 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 ππ--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. the shells are dramatic like that π
)
--arg-from-filename path β pass the contents of file path as the argument name to Nix functions.--arg-from-stdinname β pass the contents of stdin as the argument name to Nix functions.--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. way less escaping drama, obsessed πΈ--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 bestie, 3 is the fourth element β zero-indexing is just how she rolls π
--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. (yes, "contain" β we're quoting her verbatim, she's doing her best π)
-I/--includepath β 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 π¦--optionname value β set the Nix configuration option name to value. this overrides settings in the Nix configuration file (seenix.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 undernix-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/storeresolves to different places) could spit out different results. Usually that's fine β except when you deploy builds to machines where/nix/storeresolves somewhere else. If you're sure you're not gonna do that, you can setNIX_IGNORE_SYMLINK_STOREto1. π
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
mount8 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 thelibstore:store-dirbuild 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 thelog-dirbuild 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, wherelocalstatediris 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 todaemon-socket/socketinside the state directory (seeNIX_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 to1and Nix prints some evaluation statistics, like how many values got allocated. πNIX_COUNT_CALLSβ set it to1and 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 to384 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:
$NIX_CONFIG_HOME, if it is defined- Otherwise, the platform default (e.g.
$XDG_CONFIG_HOME/nixon 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 bynix-shell. It can have the valuespureorimpure.
π 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 afterXDG_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
- 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