NIX-STORE-VERIFY-PATH(1)

πŸ’… nix-store --verify-path(1) β€” General Commands Manual

okay bestie, welcome to nix-store --verify-path(1), it's literally your new fave lil detective πŸ’–


✨ Name ✨

nix-store --verify-path β€” check path contents against the Nix database πŸ”πŸ¦‹

🌸 Synopsis 🌸

nix-store --verify-path paths…

πŸ’œ Description πŸ’œ

So the --verify-path operation is the vibe check for your store paths fr fr πŸ‘‘. It takes the contents of the store paths you hand it and compares them against their cryptographic hashes that are chilling in Nix's database.

For every single path that's changed? It prints a warning message πŸ“’. That's it, that's the tea.

The exit status is 0 if no path has changed, and 1 otherwise. No cap.


πŸŽ€ Options πŸŽ€

The following options are allowed for all nix-store operations, but ngl they may not always have an effect πŸ™ˆ.

  • --add-root path β€” causes the result of a realisation (--realise and --force-realise) to be registered as a root of the garbage collector 🌈. The path will be created as a symlink to the resulting store path. On top of that, a uniquely named symlink to path will be created in /nix/var/nix/gcroots/auto/. Like, 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

So basically, when /home/eelco/bla/result gets removed, the GC root sitting in the auto directory becomes a dangling symlink and will just be ignored by the collector 🫢. Iconic behaviour honestly.

⚠️ Warning ⚠️ Note that it is not possible to move or rename GC roots, because the symlink in the auto directory will still point to the old location πŸ’€. So like, don't try it.

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



🌈 Common Options 🌈

okay so listen bestie πŸ’– β€” most Nix commands are literally holding hands and accepting the same little squad of command-line options. Here's the whole crew, no gatekeeping:

  • --help β€” prints out a lil summary of the command syntax and then dips. 🫢
  • --version β€” spits the Nix version number onto standard output and bounces.
  • --verbose / -v β€” cranks up how chatty the diagnostic messages on standard error are. Here's the tea, though: for every Nix operation, what lands on standard output is well-defined, and any diagnostic info goes to standard error, never to standard output. Clean separation, we love to see it. ✨

You can stack this option over and over. 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 up to. This 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. πŸ’€
  • --quiet β€” turns the diagnostic verbosity on standard error down. It's the inverse option to -v / --verbose. You can give this one repeatedly too β€” peek the verbosity level list right above. πŸ™ˆ
  • --log-format format β€” lets you switch up how the log output looks, where format is one of these:
    • raw β€” the raw format, exactly 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, bestie.
  • bar β€” only displays a progress bar during the builds.
  • bar-with-logs β€” displays the raw logs, with the progress bar chillin' at the bottom.
  • --no-build-output / -Q β€” by default, whatever builders write to standard output and standard error gets echoed to the Nix command's standard error. This option shuts that behaviour down. But heads up πŸ‘€: the builder's standard output and error are always written to a log file in prefix/nix/var/log/nix.
  • --max-jobs / -j number β€” sets the max number of build jobs Nix will run in parallel, to number. Say auto to just use however many CPUs the system has. The default comes from the max-jobs configuration setting, which itself defaults to 1. A higher value is the move on SMP systems, or when you wanna exploit I/O latency. πŸ”₯

Setting it to 0 means no building on the local machine at all β€” which is exactly what you want when builds should only happen on remote builders. πŸ‘‘

  • --cores β€” sets the value of the NIX_BUILD_CORES environment variable when builders get invoked. Builders can use this variable however they like to control their 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 on 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 is specified by the max-silent-time configuration setting. 0 means no time-out. πŸ•°οΈ
  • --timeout β€” sets the max number of seconds a builder can run. The default is specified by the timeout configuration setting. 0 means no timeout.
  • --keep-going / -k β€” keeps going in case of failed builds, to the greatest extent possible. Like, if building an input of some derivation fails, Nix will still build the other inputs β€” just not the derivation itself. Without this option, Nix stops if any build fails (except for builds of substitutes), possibly killing builds in progress (that's the parallel or distributed build situation, iykyk). πŸ’…
  • --keep-failed / -K β€” says that in case of a build failure, the temporary directory (usually in /tmp) where the build happened should not get deleted. The path of the build directory gets printed as an informational message.
  • --fallback β€” whenever Nix tries to build a derivation for which substitutes are known for each output path, but realising those output paths through the substitutes fails, it falls back on building the derivation.

The most common scenario where this slays is when we've registered substitutes to do binary distribution from, say, a network repository. If the repository is down, realising the derivation will fail. With this option on, Nix builds the derivation instead β€” so installation from binaries falls back on installation from source. It's not the default, because honestly you generally don't want a transient failure in getting the substitutes to lead to a full build from source (with all the resource consumption that drags along with it). 😭

  • --readonly-mode β€” when this is on, no attempt is made to open the Nix database. Most Nix operations do need database access, so those operations will just fail. πŸ€·β€β™€οΈ
  • --arg name value β€” accepted by nix-env, nix-instantiate, nix-shell and nix-build. When evaluating Nix expressions, the expression evaluator automatically tries to call functions it encounters. It can auto-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 like, if the evaluator encounters a function with an argument named name, it'll 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 gets 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 β€” passes the contents of file path as the argument name to Nix functions.
  • --arg-from-stdin name β€” passes the contents of stdin as the argument name to Nix functions.
  • --argstr name value β€” this one's like --arg, except the value isn't a Nix expression, it's a string. So instead of --arg system \"i686-linux\" (the outer quotes are just to keep the shell happy), you can say --argstr system i686-linux. πŸ¦‹
  • --attr / -A attrPath β€” selects an attribute from the top-level Nix expression being evaluated. (nix-env, nix-instantiate, nix-build and nix-shell only, bestie.) 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. Check out nix-env --install for some concrete examples.

And 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. So many layers, obsessed. ✨

  • --eval-store store-url β€” the URL of the Nix store to use for evaluation, i.e. where to store derivations (.drv files) and inputs referenced by them.
  • --expr / -E β€” interprets 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, hand your expression to the nix-shell --packages convenience flag instead. 🫢

  • -I / --include path β€” adds an entry to the list of search paths used to resolve lookup paths. You can give this option multiple times.

Paths added through -I take precedence over the nix-path configuration setting and the NIX_PATH environment variable. Main character energy, honestly. πŸ‘‘

  • --impure β€” allows access to mutable paths and repositories.
  • --option name value β€” sets the Nix configuration option name to value. This overrides settings in the Nix configuration file (see nix.conf5).
  • --repair β€” fixes corrupted or missing store paths by redownloading or rebuilding them. But ngl, 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.

🌈 Common Environment Variables 🌈

Bestie. Gather round. Most Nix commands are lowkey eavesdropping on these environment variables, so if you set one of them, expect the whole vibe of the command to shift accordingly. πŸ‘€


Configuration environment variables

These ones control how Nix loads up its config. For the full tea, see the configuration file documentation.

  • 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. So extra. πŸ’…

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 stops "impure" builds from happening. Why? Because builders sometimes "canonicalise" paths by resolving every symlink component, so a build on one machine (where /nix/store resolves somewhere different) could give you different results than on another machine. Usually that's fine, except when builds get deployed to machines where /nix/store resolves differently. If you're genuinely sure you're not gonna do that 😌, you can set NIX_IGNORE_SYMLINK_STORE to 1.

Heads up though: if you're symlinking the Nix store so you can stash it on a filesystem other than the root one, on Linux you're way better off using bind mount points, like this:

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

Go consult the mount 8 manual page for the details, bestie.

  • 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, determined 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 the location of the Nix log directory. On Unix, the default is /nix/var/log/nix, set at compile time by the log-dir build option. On Windows, there is no compile-time setting; the default is %PROGRAMDATA%\nix\log, determined at runtime using the %PROGRAMDATA% Known Folder.

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

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

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 used to talk to the Nix daemon. It defaults to daemon-socket/socket inside the state directory (see NIX_STATE_DIR).

See the Local Daemon Store documentation for the deets on how the socket path gets resolved.

  • TMPDIR β€” use this directory to store temporary files. In particular that includes temporary build directories, which can eat up substantial amounts 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. Numbers girlies rise. πŸ“Š
  • 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 has been 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 all that garbage-collection overhead.
  • 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. Periodt.

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 supports per-user configuration, state, and cache directories. The following environment variables override the locations for these directories:

  • [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 these aren't 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 (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. Glow-up behavior honestly ✨

When use-xdg-base-directories is enabled, the configuration directory is resolved as:

  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 if the current environment was set up by nix-shell. It can have the values pure or impure.

πŸ¦‹ Appendix: OS-specific conventions πŸ¦‹

None of this is Nix-specific, it's just stuff referenced above. Fyi.

Unix: XDG Base Directories

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

The following environment variables are used:

  • [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) β€” colon-separated list of additional configuration base directories, searched after XDG_CONFIG_HOME

Windows: Known Folders

On Windows, Known Folders provide standard locations for application data on Windows.

The relevant folders are:

  • [%APPDATA%]{#env-APPDATA} β€” per-user roaming application data
  • [%LOCALAPPDATA%]{#env-LOCALAPPDATA} β€” per-user local application data
  • [%PROGRAMDATA%]{#env-PROGRAMDATA} β€” system-wide application data

πŸ’– Example πŸ’–

Say you wanna verify the integrity of the svn command and all its dependencies, bestie:

$ nix-store --verify-path $(nix-store --query --requisites $(which svn))

Slay. That's the whole thing. Go protect your store integrity, you absolute icon πŸ‘‘πŸŒˆ


And that's a wrap on the whole nix-store --verify-path(1) page, fr fr β€” and like every good glow-up, it comes signed off with its own source/version and date line at the bottom, which is just the manual itself: nix-store --verify-path(1). Take that credit, you earned it. πŸ’…πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from