NIX-STORE-QUERY(1)
okay bestie, this is nix-store --query(1) π
β the man page that lets you grill store paths for information. She's giving detective, she's giving database, she's giving absolute icon. No cap.
πΈ NAME πΈ
nix-store --query β display information about store paths. That's it, that's the whole name, and she ate. β¨
π¦ SYNOPSIS π¦
the exact lineup, bestie:
nix-store {--query | -q} {--outputs | --requisites | -R | --references |
--referrers | --referrers-closure | --deriver | -d | --valid-derivers |
--graph | --tree | --binding name | -b name | --hash | --size | --roots}
[--use-output] [-u] [--force-realise] [-f] pathsβ¦
π DESCRIPTION π
The --query operation displays various bits of information about the store paths. The queries are described below. You can specify at most one query at a time. The default query is --outputs. π
The paths may also be symlinks from outside of the Nix store, to the Nix store. In that case, the query is applied to the target of the symlink. So the symlink is just the messenger. π«Ά
π COMMON QUERY OPTIONS π
--use-output/-uβ For each argument to the query that is a store derivation, apply the query to the output path of the derivation instead. β¨--force-realise/-fβ Realise each argument to the query first (seenix-store --realise). Make it real before you ask it questions. π
π₯ QUERIES π₯
Pick one, bestie β at most one, remember? Here's the menu:
--outputsβ Prints out the output paths of the store derivationspaths. These are the paths that will be produced when the derivation is built. π¦--referencesβ Prints the set of references of the store pathspaths, that is, their immediate dependencies. (For all dependencies, use--requisites.) π--requisites/-Rβ Prints out the set of requisites (better known as the closure) of the store pathpaths.
This query has one option:
--include-outputsβ Also include the existing output paths of store derivations, and their closures.
This query can be used to implement various kinds of deployment. A source deployment is obtained by distributing the closure of a store derivation. A binary deployment is obtained by distributing the closure of an output path. A cache deployment (combined source/binary deployment, including binaries of build-time-only dependencies) is obtained by distributing the closure of a store derivation and specifying the option --include-outputs. π
--referrersβ Prints the set of referrers of the store pathspaths, that is, the store paths currently existing in the Nix store that refer to one ofpaths. Note that contrary to the references, the set of referrers is not constant; it can change as store paths are added or removed. She's fluid, she's shifting, she's not staying put. π--referrers-closureβ Prints the closure of the set of store pathspathsunder the referrers relation; that is, all store paths that directly or indirectly refer to one ofpaths. These are all the paths currently in the Nix store that are dependent onpaths. π--deriver/-dβ Prints the deriver that was used to build the store pathspaths. If the path has no deriver (e.g., if it is a source file), or if the deriver is not known (e.g., in the case of a binary-only deployment), the stringunknown-deriveris printed. The returned deriver is not guaranteed to exist in the local store, for example when paths were substituted from a binary cache. Use--valid-deriversinstead to obtain valid paths only. π--valid-deriversβ Prints a set of derivation files (.drv) which are supposed to produce said paths when realized. Might print nothing, for example for source paths or paths substituted from a binary cache. She can ghost you, and that's valid. π--graphβ Prints the references graph of the store pathspathsin the format of thedottool of AT&T's Graphviz package. This can be used to visualise dependency graphs. To obtain a build-time dependency graph, apply this to a store derivation. To obtain a runtime dependency graph, apply it to an output path. π--treeβ Prints the references graph of the store pathspathsas a nested ASCII tree. References are ordered by descending closure size; this tends to flatten the tree, making it more readable. The query only recurses into a store path when it is first encountered; this prevents a blowup of the tree representation of the graph. Very demure, very mindful. π³--graphmlβ Prints the references graph of the store pathspathsin the GraphML file format. This can be used to visualise dependency graphs. To obtain a build-time dependency graph, apply this to a store derivation. To obtain a runtime dependency graph, apply it to an output path. πΊοΈ--bindingname /-bname β Prints the value of the attributename(i.e., environment variable) of the store derivationspaths. It is an error for a derivation to not have the specified attribute. So don't ask for something that isn't there, bestie. π--hashβ Prints the SHA-256 hash of the contents of the store pathspaths(that is, the hash of the output ofnix-store --dumpon the given paths). Since the hash is stored in the Nix database, this is a fast operation. Speedy queen. β‘--sizeβ Prints the size in bytes of the contents of the store pathspathsβ to be precise, the size of the output ofnix-store --dumpon the given paths. Note that the actual disk space required by the store paths may be higher, especially on filesystems with large cluster sizes. She's precise, not wrong. π--rootsβ Prints the garbage collector roots that point, directly or indirectly, at the store pathspaths. π±
π OPTIONS π
The following options are allowed for all nix-store operations, but may not always have an effect. π
--add-rootpath β Causes the result of a realisation (--realiseand--force-realise) to be registered as a root of the garbage collector.pathwill be created as a symlink to the resulting store path. In addition, a uniquely named symlink topathwill 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.
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). π’
π Common Options π
Okay so most Nix commands accept all of these, bestie. Like, the whole family. Here's the lineup π«Ά
--helpβ prints out a summary of the command syntax and then dips. That's the whole thing β¨--versionβ prints out the Nix version number on standard output and exits. slay.--verbose/-vβ cranks up the level of verbosity of diagnostic messages printed on standard error. Important vibe note: for each Nix operation, the info printed on standard output is well-defined; any diagnostic info goes on standard error, never on standard output. no cap.
This option may be specified repeatedly. Currently, the following verbosity levels exist, queen π
0βErrors onlyβ β only print messages explaining why the Nix invocation failed. awkward but necessary π1βInformationalβ β print useful messages about what Nix is doing. This is the default, bestie.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. it's giving unhinged and we respect it π
--quietβ decreases the level of verbosity of diagnostic messages printed on standard error. It's the inverse option to-v/--verbose. May be specified repeatedly. See the verbosity levels list above β¬οΈ--log-formatformat β lets you swap out the output of the log format. format has 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 get too attached.
barβ only display a progress bar during the builds.bar-with-logsβ display the raw logs, with the progress bar at the bottom. the best of both worlds tbh π
--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. Note that the builder's standard output and error are always written to a log file inprefix/nix/var/log/nix. like, always always. π--max-jobs/-jnumber β sets the maximum number of build jobs Nix will perform in parallel to number. Sayautoto use the number of CPUs in the system. The default is specified by 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. go touch grass locally, build in the cloud β¨
--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 the builder should use all available CPU cores in the system. all of them. every single one π₯--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 themax-silent-timeconfiguration setting.0means no time-out. silence really is golden here π--timeoutβ sets the maximum number of seconds a builder can run. The default is specified by thetimeoutconfiguration setting.0means no timeout.--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). the way that it just keeps goingβ¦ πͺ--keep-failed/-Kβ specifies 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 is printed as an informational message. free souvenirs π--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 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. 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). lowkey a resource-hungry main character move π
--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, don't touch, and also most stuff just breaks π--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.) quotes are the drama, bestie π
--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. so much less escaping drama β¨--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, it's zero-indexed, yes, that means 3 is the fourth one, don't @ me π§
--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 contains the built packages ready for use, give your expression to the nix-shell --packages convenience flag instead. π
-I/--includepath β 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. stacked. π
--impureβ allow access to mutable paths and repositories. living dangerously, love that for you π₯--optionname value β set the Nix configuration option name to value. This overrides settings in the Nix configuration file (seenix.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 undernix-store --repair-path. heal the store, but at what cost π
π Note: see man nix.conf for overriding configuration settings with command line flags.
π οΈ Common Environment Variables π οΈ
Like, most Nix commands read these. They're the whole vibe-setting layer under everything, bestie. π
βοΈ Configuration environment variables
These three control how Nix loads up its config. The configuration file docs have the full tea, but here's the rundown:
NIX_CONF_DIRβ swaps out the system configuration directory for whatever you point it at.NIX_USER_CONF_FILESβ swaps out where the user configuration files live.NIX_CONFIGβ lets you hand Nix configuration settings inline, right there, no file needed. Iconic.
π¬ 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 at all. Why? To prevent "impure" builds. See, builders sometimes "canonicalise" paths by resolving every single symlink component, so builds on different machines (where/nix/storeresolves to different places) could give you different results. Usually that's fine β except when you deploy builds to machines where/nix/storeresolves somewhere else. If you're sure that's not your situation, setNIX_IGNORE_SYMLINK_STOREto1.
Heads up: if you're symlinking the Nix store so you can park 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 man page for the details, bestie.
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.
Peep the Store Types chapter, kay? Every store has a store setting that links back to this one 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 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 all have per-store settings that override this. π
NIX_STATE_DIRβ overrides the location of the Nix state directory. On Unix the default is${localstatedir}/nix, wherelocalstatediris a compile-time build option that defaults to/nix/var. On Windows there's no compile-time setting; the default is%PROGRAMDATA%\nix\state, worked out at runtime using the%PROGRAMDATA%Known Folder.
Same deal as above: Local Store, Local Daemon Store, and Experimental SSH Store with filesystem mounted each have per-store settings that override it.
NIX_DAEMON_SOCKET_PATHβ overrides the path to the Unix domain socket that talks to the Nix daemon. Defaults todaemon-socket/socketinside the state directory (checkNIX_STATE_DIRπ).
The Local Daemon Store documentation explains exactly how the socket path gets resolved, if you wanna go deep.
TMPDIRβ use this directory for temporary files. It specifically includes temporary build directories, and those can eat up a substantial amount of disk space, so watch it. Default is/tmp.NIX_REMOTEβ overrides the store setting.
π§ Nix language evaluator settings
NIX_SHOW_STATSβ if you set it to1, Nix prints out some evaluation statistics, like how many values got allocated. β¨NIX_COUNT_CALLSβ set it to1and Nix tells you how often functions were called during Nix expression evaluation. Super useful for profiling your Nix expressions, no cap.GC_INITIAL_HEAP_SIZEβ if Nix was configured to use the Boehm garbage collector, this sets the initial heap size in bytes. It defaults to384 MiB. Set it low and you use less memory, but runtime goes up because of all the garbage collection overhead. Trade-offs, bestie. πNIX_PATHβ a colon-separated list of search path entries used to resolve lookup paths.
This env var overrides the value of the nix-path configuration setting.
And 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 does per-user configuration, state, and cache directories, and these env vars override where those live:
- user configuration directory (docs anchor it as
#user-conf-dir):NIX_CONFIG_HOME(anchor:#env-NIXCONFIGHOME) - user state directory:
NIX_STATE_HOME(anchor:#env-NIXSTATEHOME) - user cache directory:
NIX_CACHE_HOME(anchor:#env-NIXCACHEHOME)
When you don't set those, 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
Now, for backwards compatibility, the legacy Nix commands (think nix-env, nix-channel) use dotfiles in $HOME instead of these directories β unless use-xdg-base-directories is enabled. The new Nix commands (the experimental ones) use the proper directories by default. Slay.
When use-xdg-base-directories is enabled, the configuration directory gets resolved like this:
$NIX_CONFIG_HOME, if it is defined- Otherwise, the platform default (e.g.
$XDG_CONFIG_HOME/nixon Unix)
Same logic 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 π
None of this is Nix-specific, it's just referenced up above, but we're including it because completeness is the whole brand. π
π§ Unix: XDG Base Directories
The XDG Base Directory Specification defines the standard spots for user-specific configuration, state, and cache files on Unix systems.
Here's what gets used:
XDG_CONFIG_HOME(anchor:#env-XDGCONFIGHOME) β default~/.configXDG_STATE_HOME(anchor:#env-XDGSTATEHOME) β default~/.local/stateXDG_CACHE_HOME(anchor:#env-XDGCACHEHOME) β default~/.cacheXDG_CONFIG_DIRS(anchor:#env-XDGCONFIGDIRS) β default/etc/xdg. It's a colon-separated list of additional configuration base directories, and they get searched afterXDG_CONFIG_HOME.
πͺ Windows: Known Folders
On Windows, Known Folders are the standard locations for application data. The relevant ones are:
%APPDATA%(anchor:#env-APPDATA) β per-user roaming application data%LOCALAPPDATA%(anchor:#env-LOCALAPPDATA) β per-user local application data%PROGRAMDATA%(anchor:#env-PROGRAMDATA) β system-wide application data
π₯ EXAMPLES π₯
Okay this is the fun part, bestie. Look at what this thing can do. π
Print the closure (the runtime dependencies) of the svn program in the current user environment:
$ nix-store --query --requisites $(which svn)
/nix/store/5mbglq5ldqld8sj57273aljwkfvj22mc-subversion-1.1.4
/nix/store/9lz9yc6zgmc0vlqmn2ipcpkjlmbi51vv-glibc-2.3.4
...
Print the build-time dependencies of svn:
$ nix-store --query --requisites $(nix-store --query --deriver $(which svn))
/nix/store/y6qa66l9h0pw161crnlk6y16rdrcljx4-grep-2.5.1.tar.bz2.drv
/nix/store/z716h753s97jhnzvfank2srqbljswpgm-gcc-wrapper.sh
/nix/store/f39x0q73rjdyvzm93y9wrkfr6x39lb7f-glibc-2.3.4.drv
... lots of other paths ...
The difference from the last example is that here we're asking for the closure of the derivation (-qd), not the closure of the output path that holds svn. Subtle but so real.
Show the build-time dependencies as a tree:
$ nix-store --query --tree $(nix-store --query --deriver $(which svn))
/nix/store/7i5082kfb6yjbqdbiwdhhza0am2xvh6c-subversion-1.1.4.drv
+---/nix/store/vxnmkc8l8d2ijjha4xwhkfgx9vvc3q4c-builder.sh
+---/nix/store/rn9776dy82n5qrgz7xbcl1iw4vfkcrkk-bash-3.0.drv
| +---/nix/store/x9j20hz6bln1crzn55qifk0bbsm8v5ac-bash
| +---/nix/store/ajnn1mcm45wjvn0rlc22gvx2cwhjnazx-builder.sh
...
Show all paths that depend on the same OpenSSL library as svn:
$ nix-store --query --referrers $(nix-store --query --binding openssl $(nix-store --query --deriver $(which svn)))
/nix/store/23ny9l9wixx21632y2wi4p585qhva1q8-sylpheed-1.0.0
/nix/store/5mbglq5ldqld8sj57273aljwkfvj22mc-subversion-1.1.4
/nix/store/dpmvp969yhdqs7lm2r1a3gng7pyq6vy4-subversion-1.1.3
/nix/store/l51240xqsgg8a7yrbqdx1rfzyv6l26fx-lynx-2.8.5
Show all paths that directly or indirectly depend on the Glibc (C library) used by svn:
$ nix-store --query --referrers-closure $(ldd $(which svn) | grep /libc.so | awk '{print $3}')
/nix/store/034a6h4vpz9kds5r6kzb9lhh81mscw43-libgnomeprintui-2.8.2
/nix/store/15l3yi0d45prm7a82pcrknxdh6nzmxza-gawk-3.1.4
...
Quick note: ldd is a command that prints out the dynamic libraries used by an ELF executable. π§
Make a picture of the runtime dependency graph of the current user environment:
$ nix-store --query --graph ~/.nix-profile | dot -Tps > graph.ps
$ gv graph.ps
Show every garbage collector root that points to a store path that depends on svn:
$ nix-store --query --roots $(which svn)
/nix/var/nix/profiles/default-81-link
/nix/var/nix/profiles/default-82-link
/home/eelco/.local/state/nix/profiles/profile-97-link
And that's a wrap on the whole thing, bestie!! πβ¨ You made it to the very end of nix-store --query(1) β the footer's got the page name right there, with the Nix version and the date hanging out next to it. Go forth and query some closures. Main character energy only. π
ππ
π¦ 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