NIX-STORE-VERIFY(1)

๐ŸŽ€ nix-store --verify โ€” check Nix database for consistency ๐ŸŽ€

okay bestie, welcome to the nix-store --verify(1) page โ€” this is the General Commands Manual energy, and we are getting into it ๐Ÿ’–


โœจ Name โœจ

nix-store --verify โ€” check Nix database for consistency ๐Ÿ‘‘


๐ŸŒธ Synopsis ๐ŸŒธ

nix-store --verify [--check-contents] [--repair]

๐Ÿ’… Description ๐Ÿ’…

okay so the --verify operation does a whole vibe check on your Nix setup, and it's checking two things at once, no cap:

  • the internal consistency of the Nix database, and
  • the consistency between the Nix database and the Nix store ๐Ÿฆ‹

and here's the slay part: any inconsistencies it runs into? automatically repaired. it just handles it, periodt.

where do these inconsistencies even come from, you ask? typically they're the result of the Nix store or the database getting modified by non-Nix tools (rude ๐Ÿ˜ญ), or from bugs in Nix itself. iykyk.

This operation has the following options:

  • --check-contents โ€” checks that the contents of every valid store path has not been altered by computing a SHA-256 hash of the contents and comparing it with the hash stored in the Nix database at build time ๐Ÿ”ฅ Paths that have been modified are printed out. and listen, for large stores, --check-contents is obviously quite slow. like, obviously. so be patient bestie ๐ŸŒธ
  • --repair โ€” if any valid path is missing from the store, or (if --check-contents is given) the contents of a valid path has been modified, then it tries to repair the path by redownloading it โœจ See nix-store --repair-path for details.

โญ Options โญ

the following options are allowed for all nix-store operations, but may not always have an effect. (the way that's just how it is ๐Ÿ™ˆ)

  • --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 ๐Ÿ‘‘

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 like, don't try it bestie, it will not work ๐Ÿ’€

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) ๐ŸŽ€


<div align="center">โ€” part 1 of 3, keep scrolling ๐Ÿ’– โ€”</div>

โœจ COMMON OPTIONS โœจ

okay so bestie, most Nix commands speak this same lil language of flags ๐Ÿ’ฌ like they all got together and agreed on a shared vibe, and these are the ones you'll keep bumping into. memorize these and you're basically fluent, no cap ๐ŸŒธ


  • --help โ€” prints out a summary of the command syntax and then exits. that's it, that's the whole thing, iconic behaviour honestly ๐Ÿ’…
  • --version โ€” prints out the Nix version number on standard output and exits. quick lil flex.
  • --verbose, -v โ€” bumps UP the level of verbosity of diagnostic messages printed on standard error. here's the deal bestie: for each Nix operation, the info printed on standard output is well-defined โ€” any diagnostic info goes to standard error, never on standard output. so stdout stays clean, stderr is where the yapping lives ๐Ÿ—ฃ๏ธ

this option can be specified repeatedly (so you can stack it like -vv). right now these are the verbosity levels that exist:

  • 0 "Errors only" โ€” only prints messages explaining why the Nix invocation failed ๐Ÿ˜ญ
  • 1 "Informational" โ€” prints useful messages about what Nix is doing. this one is the default โœจ
  • 2 "Talkative" โ€” prints more informational messages
  • 3 "Chatty" โ€” prints even more informational messages
  • 4 "Debug" โ€” prints debug information
  • 5 "Vomit" โ€” prints vast amounts of debug information ๐Ÿคข (the name is not a joke, it is accurate)
  • --quiet โ€” turns the verbosity of diagnostic messages on standard error DOWN. this is the inverse option to -v / --verbose. yeah it's the opposite-gender bestie of -v ๐Ÿซถ

this option can also be specified repeatedly, and it walks back through those same verbosity levels listed above.

  • --log-format format โ€” changes the output of the log format, where format is one of:
    • 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 like... don't hardcode against the vibes of that field, bestie ๐Ÿ˜ฌ
  • bar โ€” only display a progress bar during the builds
  • bar-with-logs โ€” display the raw logs, with the progress bar at the bottom โœจ
  • --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 behaviour. note that the builder's standard output and error are always written to a log file in prefix/nix/var/log/nix. so nothing gets lost, it's just not shouted at you ๐Ÿ“
  • --max-jobs, -j number โ€” sets the maximum number of build jobs Nix will do in parallel to number. say 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. setting it to 0 disallows building on the local machine, which is useful when you want builds to happen only on remote builders ๐Ÿ›ฐ๏ธ
  • --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 the builder should use all available CPU cores in the system ๐Ÿ”ฅ
  • --max-silent-time โ€” sets the maximum number of seconds 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 โฐ
  • --timeout โ€” sets the maximum number of seconds a builder can run. the default is specified by the timeout configuration setting. 0 means no timeout โณ
  • --keep-going, -k โ€” keep going in case of failed builds, to the greatest extent possible. that means 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) ๐Ÿ’€
  • --keep-failed, -K โ€” says 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 can go investigate the crime scene.
  • --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 instead.

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. so installation from binaries falls back on installation from source. this option is not the default since it's 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 yes bestie it's a glow-up but it's an expensive one ๐Ÿ’ธ

  • --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 ๐Ÿšซ๐Ÿ—„๏ธ
  • --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.) ๐Ÿ˜ฎโ€๐Ÿ’จ

  • --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 one 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 there to keep the shell happy) you can just say --argstr system i686-linux ๐Ÿ’… so much chiller
  • --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 means fourth, that's just how it is, zero-indexed broke the group chat)

  • --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 ๐Ÿšโœจ

  • -I, --include path โ€” add an entry to the list of search paths used to resolve lookup paths ๐Ÿ” this option may be given multiple times. paths added through -I take precedence over the nix-path configuration setting and the NIX_PATH environment variable ๐Ÿ‘‘
  • --impure โ€” allow access to mutable paths and repositories ๐ŸŒ€
  • --option name value โ€” set the Nix configuration option name to value. this overrides settings in the Nix configuration file (see nix.conf(5)) โš™๏ธ
  • --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 โš ๏ธ
๐Ÿ“ Note: see man nix.conf for overriding configuration settings with command line flags. iykyk ๐ŸŽ€

โœจ Common Environment Variables โœจ

ok so most Nix commands are out here reading env vars like it's their whole personality, so bestie you need to know them ๐Ÿ’…


๐Ÿ› ๏ธ Configuration environment variables

These cuties control how Nix loads up its configuration. For the full tea, go look at the configuration file documentation. ๐Ÿ“–

  • NIX_CONF_DIR โ€” overrides where the system configuration directory lives.
  • NIX_USER_CONF_FILES โ€” overrides where the user configuration files live.
  • NIX_CONFIG โ€” lets you just... hand Nix its configuration settings inline. no file needed. slay โœจ

๐Ÿฌ Store setting environment variables

  • NIX_IGNORE_SYMLINK_STORE โ€” okay so normally the Nix store directory (usually /nix/store) is not allowed to have any symlink components in it. why? to stop "impure" builds, periodt. the thing is, builders sometimes "canonicalise" paths by resolving every symlink component, so builds on different machines (where /nix/store resolves to different places) could give you different results ๐Ÿ˜ญ. normally that's whatever, EXCEPT when builds get deployed to machines where /nix/store resolves differently. if you're 100% sure you're never gonna do that, set NIX_IGNORE_SYMLINK_STORE to 1.

also heads up: if you're symlinking the Nix store to shove it on a different filesystem than root, on Linux you're way better off using bind mount points, like:

$ mkdir /nix
$ mount -o bind /mnt/otherdisk/nix /nix

go read the mount 8 manual page for the details, bestie.

  • NIX_STORE_DIR โ€” overrides where the Nix store lives. on Unix the default is /nix/store, and it's 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. ๐ŸชŸ

also go peek at 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 that defaults to /nix/var. on Windows there's no compile-time setting; the default is %PROGRAMDATA%\nix\state, determined at runtime using the %PROGRAMDATA% Known Folder.

same deal as above: the Local Store, Local Daemon Store, and Experimental SSH Store with filesystem mounted have per-store settings that override this. ๐Ÿ’œ

  • NIX_DAEMON_SOCKET_PATH โ€” overrides the path to the Unix domain socket that talks to the Nix daemon. defaults to daemon-socket/socket inside the state directory (see NIX_STATE_DIR).

check the Local Daemon Store documentation for how the socket path actually gets resolved. ๐Ÿ”Œ

  • TMPDIR โ€” use this directory for temporary files. yes, this includes temporary build directories, and those can eat substantial amounts of disk space, no cap. default is /tmp.
  • NIX_REMOTE โ€” overrides the store setting.

๐Ÿง  Nix language evaluator settings

  • NIX_SHOW_STATS โ€” set it to 1 and Nix prints out some evaluation statistics, like how many values got allocated. numbers go brrr ๐Ÿ“Š
  • NIX_COUNT_CALLS โ€” set it to 1 and Nix tells you how often functions got called during Nix expression evaluation. genuinely so useful for profiling your Nix expressions.
  • GC_INITIAL_HEAP_SIZE โ€” if Nix was configured to use the Boehm garbage collector, this sets the initial heap size in bytes. default is 384 MiB. setting it low = less memory used but longer runtime, because garbage collection overhead is always lurking ๐Ÿ™ˆ
  • NIX_PATH โ€” a colon-separated list of search path entries used to resolve lookup paths.

this env var overrides whatever the nix-path configuration setting says.

you can also extend it with the -I option. ๐Ÿซถ

Example $ export NIX_PATH=/home/eelco/Dev:nixos-config=/etc/nixos

and if NIX_PATH is set to an empty string, resolving search paths will always fail. iconic, honestly.

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, and these env vars let you override where each one goes:

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

when you don't set them, the defaults depend on your platform:

  • on Unix, it's the XDG base directories: $XDG_CONFIG_HOME/nix, $XDG_STATE_HOME/nix, $XDG_CACHE_HOME/nix
  • on Windows, it's the Windows Known Folders: %APPDATA%\nix\config, %LOCALAPPDATA%\nix\state, %LOCALAPPDATA%\nix\cache

for backwards compatibility though, legacy Nix commands (hi nix-env, hi nix-channel ๐Ÿ‘‹) use dotfiles in $HOME instead of these directories โ€” unless use-xdg-base-directories is enabled. the new Nix commands (experimental) just use the proper directories by default. glow up โœจ

when use-xdg-base-directories is enabled, the configuration directory gets resolved like this:

  1. $NIX_CONFIG_HOME, if it's defined
  2. otherwise, the platform default (like $XDG_CONFIG_HOME/nix on Unix)

and it's literally the same story 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 ๐ŸŒˆ

just so you know, none of this is Nix-specific โ€” it's just stuff that got referenced up above. ๐Ÿ“Ž

๐Ÿง Unix: XDG Base Directories

the XDG Base Directory Specification defines the standard locations for user-specific configuration, state, and cache files on Unix systems. ๐Ÿ’…

these are the env vars 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 give you the standard locations for application data. the relevant ones 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, we ate that ๐Ÿ“๐Ÿ’– this was the nix-store --verify(1) manual, and yeah โ€” the footer's got the source and version plus a date stamp down there, so if you ever need to cite exactly which build of the docs you read, that's where the receipts live. go forth and verify, queen ๐Ÿ‘‘๐ŸŒธ

๐Ÿ“ฆ where this page comes from