NIX-ENV-QUERY(1)
๐ nix-env --query โ the "so what do I even have installed??" command
ok so this page is from the General Commands Manual (section 1), and bestie, it's the nix-env --query one. It's giving "let me peek inside my Nix world and tell you everything." ๐ฆ
โจ Name โจ
nix-env --query โ display information about packages ๐
๐ Synopsis ๐
nix-env {--query | -q} namesโฆ [--installed | --available | -a]
[{--status | -s}] [{--attr-path | -P}] [--no-name] [{--compare-versions
| -c}] [--system] [--drv-path] [--out-path] [--description] [--meta]
[--xml] [--json] [{--prebuilt-only | -b}] [{--attr | -A} attribute-path]
๐ Description ๐
The query operation is literally just "tell me things." It displays information about either:
- the store paths that are installed in the current generation of the active profile (that's
--installed), or - the derivations that are available for installation in the active Nix expression (that's
--available).
so either "what's already in my world" or "what could be in my world." vibe check โ
It only prints info about derivations whose symbolic name matches one of names. no cap. ๐
And the derivations come out sorted by their name attributes. organized queen behavior. ๐
๐ธ Source selection ๐ธ
These flags pick which pile of stuff the query is looking at. ๐
--installedโ the query operates on the store paths that are installed in the current generation of the active profile. this is the default, bestie, so if you don't say anything, this is what you get. ๐ซถ--available,-aโ the query operates on the derivations that are available in the active Nix expression. i.e. the stuff you could install. โจ
๐ฅ Queries ๐ฅ
These flags choose what info gets shown about the derivations you selected. You can stack multiple of them โ and when you do, the info appears in the order given here. ๐
heads up: the name of the derivation is shown unless you pass --no-name. so it's on by default, like a little name tag ๐
--xmlโ prints the result in an XML representation, suitable for automatic processing by other tools. The root element is calleditems, which contains anitemelement for each available or installed derivation. The fields discussed below are all stored in attributes of theitemelements. robot-friendly, love that for us ๐ค--jsonโ prints the result in a JSON representation suitable for automatic processing by other tools. same energy, different syntax. ๐--prebuilt-only,-bโ shows only derivations for which a substitute is registered, i.e. there's a pre-built binary available that can be downloaded in lieu of building the derivation. So basically this shows all packages that probably can be installed quickly. fast girl summer. ๐ฅ--status,-sโ prints the status of the derivation. The status is three characters:- the first is
Ior-, indicating whether the derivation is currently installed in the current generation of the active profile. (by definition this is the case for--installed, but not for--available) - the second is
Por-, indicating whether the derivation is present on the system. This tells you whether installing an available derivation will require the derivation to be built. - the third is
Sor-, indicating whether a substitute is available for the derivation.
- the first is
three little letters carrying so much lore. ๐ญ
--attr-path,-Pโ prints the attribute path of the derivation, which you can use to unambiguously select it with the--attroption available in commands that install derivations, likenix-env --install.
โ ๏ธ this option only works together with --available. don't try it alone, it's not that girl ๐
--no-nameโ suppresses printing of thenameattribute of each derivation. quiet mode for the name tag ๐--compare-versions,-cโ compares installed versions to available versions, or vice versa (if--availableis given). This is so useful for quickly seeing whether upgrades for installed packages are available in a Nix expression. A column gets added, with this meaning:<version โ a newer version of the package is available or installed. โฌ๏ธ=version โ at most the same version of the package is available or installed. โก๏ธ>version โ only older versions of the package are available or installed. โฌ๏ธ-? โ no version of the package is available or installed. ๐ซ
--systemโ prints thesystemattribute of the derivation. ๐ฅ๏ธ--drv-pathโ prints the [store path] to the [store derivation]. (the glossary links being referenced are:https://nix.dev/manual/nix/2.35/glossary.html#gloss-store-pathandhttps://nix.dev/manual/nix/2.35/glossary.html#gloss-derivation) ๐ฆ--out-pathโ prints the output path of the derivation. ๐ฆ--descriptionโ prints a short (one-line) description of the derivation, if available. The description is taken from themeta.descriptionattribute of the derivation. a lil blurb bestie ๐ซถ--metaโ prints all of the meta-attributes of the derivation.
โ ๏ธ this option is only available with--xmlor--json. it does not ride solo. ๐
โญ Options โญ
These options are allowed for all nix-env operations, but they may not always have an effect. (iykyk, sometimes they just vibe in the background.) ๐
--file,-fpath โ specifies the Nix expression (called below the active Nix expression) used by the--install,--upgrade, and--query --availableoperations to obtain derivations. The default is~/.nix-defexpr.
If the argument starts with http:// or https://, it's interpreted as the URL of a tarball that will be downloaded and unpacked to a temporary location. The tarball must include a single top-level directory containing at least a file named default.nix. ๐ฆโจ
--profile,-ppath โ specifies the profile to be used by those operations that operate on a profile (called below the active profile). A profile is a sequence of user environments called generations, one of which is the current generation. generational trauma but make it Nix ๐--dry-runโ for the--install,--upgrade,--uninstall,--switch-generation,--delete-generationsand--rollbackoperations, this flag causesnix-envto print what would be done if this flag had not been specified, without actually doing it. window shopping, no purchases ๐๏ธ
--dry-run also prints out which paths will be substituted (i.e., downloaded) and which paths will be built from source (because no substitute is available). so helpful honestly ๐ญ
--system-filtersystem โ by default, operations such as--query --availableshow derivations matching any platform. This option lets you use derivations for the specified platform system. filter it, bestie ๐
ok that's part 1 and there's more coming, don't go anywhere ๐
๐ COMMON OPTIONS ๐
okay bestie, buckle UP, because basically every Nix command out there speaks this same little dialect of flags ๐. Learn these once and you're fluent forever. No cap.
--helpโ prints a lil summary of the command syntax and then dips (exits). Your friendship bracelet of flags ๐ซถ--versionโ prints the Nix version number on standard output and peaces out. That's it, that's the whole thing โจ--verbose/-vโ turns the volume UP on diagnostic messages printed on standard error. Here's the tea: for each Nix operation, whatever goes to standard output is well-defined, and any diagnostic stuff goes to standard error, never standard output. Clean separation, obsessed.
You can stack this flag repeatedly ๐. The verbosity levels, ranked:
- 0 โErrors onlyโ โ only prints messages explaining why the Nix invocation failed ๐ญ
- 1 โInformationalโ โ useful messages about what Nix is doing. This is the default.
- 2 โTalkativeโ โ more informational messages ๐ฃ๏ธ
- 3 โChattyโ โ even MORE informational messages ๐ฌ
- 4 โDebugโ โ debug info ๐
- 5 โVomitโ โ vast amounts of debug information ๐คฎ (yes that's really the name, iconic behaviour fr)
--quietโ turns the volume DOWN on diagnostic messages on standard error. It's the inverse option to-v/--verbose. Also stackable repeatedly ๐. Same verbosity levels list as above, just read it backwards bestie ๐- *
--log-format*format โ swaps up how the log output looks. format is one of: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 hardcode against it, bestie ๐
barโ only shows a progress bar during the builds.bar-with-logsโ shows the raw logs, with the progress bar chillin' 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 flag suppresses that behaviour. But heads up: the builder's standard output and error are always written to a log file inprefix/nix/var/log/nix. Always. Periodt ๐- *
--max-jobs/-j*number โ sets the max number of build jobs Nix will run in parallel. Sayautoand it'll use the number of CPUs in the system ๐ฅ๏ธ. 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 โ super handy when you want builds to happen only on remote builders, no local nonsense โจ
--coresโ sets the value of theNIX_BUILD_CORESenvironment variable in the invocation of builders. Builders can use that variable at their own discretion 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 set, or1otherwise. The value0means the builder should use all available CPU cores in the system. Go big or go home fr ๐ฅ--max-silent-timeโ sets the max number of seconds a builder can go without producing ANY data on standard output or standard error ๐ถ. Default is specified by themax-silent-timeconfiguration setting.0means no time-out. Silence is golden but also suspicious, bestie ๐--timeoutโ sets the max number of seconds a builder can run. Default is specified by thetimeoutconfiguration setting.0means no timeout. Let it cook ๐ณ--keep-going/-kโ keeps going in case of failed builds, to the greatest extent possible. Meaning: 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). Rude, honestly ๐ญ--keep-failed/-Kโ says that in case of a build failure, the temporary directory (usually in/tmp) where the build happened should not be deleted. The path of the build directory gets printed as an informational message. Perfect for when you need to go snooping through the crime scene ๐ต๏ธโ๏ธ--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 instead ๐ช
The most common scenario where this slays: you've got registered substitutes so you can do binary distribution from, like, a network repository ๐. If the repo's down, realising the derivation fails. With this option, Nix just builds the derivation instead. So installation from binaries falls back on installation from source. It's not the default because it's generally not desirable for a transient failure in obtaining substitutes to lead to a full build from source (and all the resource consumption that comes with it ๐ฎโ๐จ)
--readonly-modeโ when you use this, no attempt is made to open the Nix database. Most Nix operations genuinely need database access, so those operations will fail. Look but don't touch energy ๐ซ- *
--arg*name value โ accepted bynix-env,nix-instantiate,nix-shellandnix-build. When evaluating Nix expressions, the evaluator will automatically try to call functions 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 gets called automatically using the value builtins.currentSystem for the system argument. You can override that with --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, bestie โ don't forget, or the shell will come for you ๐ช)
- *
--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 ๐ฅ (piping it straight in, no thoughts, just vibes) - *
--argstr*name value โ this one's 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 just say--argstr system i686-linux. So much less escaping, so much more slay ๐ - *
--attr/-A*attrPath โ selects 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 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, it's zero-indexed, don't come for me ๐
)
- *
--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 which contains the built packages ready for use, give your expression to the nix-shell --packages convenience flag instead. Different vibe, different result โจ
- *
-I/--include*path โ adds an entry to the list of search paths used to resolve lookup paths. May be given multiple times ๐
Paths added through -I take precedence over the nix-path configuration setting and the NIX_PATH environment variable. The way they get priorityโฆ queen behaviour ๐
--impureโ allows access to mutable paths and repositories. Living dangerously, love that for you ๐ช๏ธ- *
--option*name value โ sets the Nix configuration option name to value. This overrides settings in the Nix configuration file (seenix.conf5) โ๏ธ --repairโ fixes 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โ ๏ธ
Note: See man nix.conf for overriding configuration settings with command line flags.
๐ฆ ENVIRONMENT VARIABLES ๐ฆ
NIX_PROFILEโ the location of the Nix profile. Defaults to the target of the symlink~/.nix-profile, if it exists, or/nix/var/nix/profiles/defaultotherwise. Your home base, your main character address ๐ ๐
๐ Common Environment Variables ๐
okay bestie, so most Nix commands are out here reading these environment variables like it's their whole personality (because it literally is). let's get into it ๐ซถ
โ๏ธ Configuration environment variables
These ones decide how Nix loads its config. full deets live in the configuration file documentation, but here's the vibe:
NIX_CONF_DIRโ overrides the system configuration directory. yes bestie, the whole system config dir.NIX_USER_CONF_FILESโ overrides the user configuration file locations.NIX_CONFIGโ gives you configuration settings inline. no extra files needed, just vibes โจ
๐ฌ Store setting environment variables
NIX_IGNORE_SYMLINK_STOREโ so normally the Nix store directory (typically/nix/store) is not allowed to contain any symlink components. why? to prevent โimpureโ builds. builders sometimes โcanonicaliseโ paths by resolving all symlink components. so builds on different machines (where/nix/storeresolves to different locations) could yield different results. that's generally not a problem, except when builds are deployed to machines where/nix/storeresolves differently. if you're sure you're not gonna do that, you can setNIX_IGNORE_SYMLINK_STOREto1.
ngl if you're symlinking the Nix store so you can put it on another file system than the root file system, on Linux you're way better off using bind mount points, like:
$ 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 thelibstore:store-dirbuild option. on Windows, there is no compile-time setting; the default is%PROGRAMDATA%\nix\store, determined at runtime using the%PROGRAMDATA%Known Folder.
See the Store Types chapter; each 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 thelog-dirbuild 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.
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, 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 communicate with the Nix daemon. defaults todaemon-socket/socketwithin the state directory (seeNIX_STATE_DIR).
See the Local Daemon Store documentation for details on how the socket path is resolved.
TMPDIRโ use the specified directory to store temporary files. in particular, this includes temporary build directories; these can take up substantial amounts of disk space. the default is/tmp.NIX_REMOTEโ overrides the store setting.
๐ง Nix language evaluator settings
NIX_SHOW_STATSโ if set to1, Nix will print some evaluation statistics, such as the number of values allocated. cute little numbers for the girlies who love metrics.NIX_COUNT_CALLSโ if set to1, Nix will print how often functions were called during Nix expression evaluation. useful for profiling your Nix expressions, bestie.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 to a low value reduces memory consumption, but will increase runtime due to the overhead of garbage collection. trade-offs, amirite?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 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 are 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 (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 is resolved as:
$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. periodt. ๐
๐ฒ Miscellaneous environment variables
IN_NIX_SHELLโ indicator that tells if the current environment was set up bynix-shell. it can have the valuespureorimpure.
๐ Appendix: OS-specific conventions
this info is not Nix-specific, but it's referenced above, so here we are. don't skip it, bestie.
๐ง 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 afterXDG_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
๐ธ Examples ๐ธ
okay now the fun part, let's see this in action:
To show installed packages:
$ nix-env --query
bison-1.875c
docbook-xml-4.2
firefox-1.0.4
MPlayer-1.0pre7
ORBit2-2.8.3
โฆ
To show available packages:
$ nix-env --query --available
firefox-1.0.7
GConf-2.4.0.1
MPlayer-1.0pre7
ORBit2-2.8.3
โฆ
To show the status of available packages:
$ nix-env --query --available --status
-P- firefox-1.0.7 (not installed but present)
--S GConf-2.4.0.1 (not present, but there is a substitute for fast installation)
--S MPlayer-1.0pre3 (i.e., this is not the installed MPlayer, even though the version is the same!)
IP- ORBit2-2.8.3 (installed and by definition present)
โฆ
To show available packages in the Nix expression foo.nix:
$ nix-env --file ./foo.nix --query --available
foo-1.2.3
To compare installed versions to what's available:
$ nix-env --query --compare-versions
...
acrobat-reader-7.0 - ? (package is not available at all)
autoconf-2.59 = 2.59 (same version)
firefox-1.0.4 < 1.0.7 (a more recent version is available)
...
To show all packages with โzipโ in the name:
$ nix-env --query --available '.*zip.*'
bzip2-1.0.6
gzip-1.6
zip-3.0
โฆ
To show all packages with โfirefoxโ or โchromiumโ in the name:
$ nix-env --query --available '.*(firefox|chromium).*'
chromium-37.0.2062.94
chromium-beta-38.0.2125.24
firefox-32.0.3
firefox-with-plugins-13.0.1
โฆ
To show all packages in the latest revision of the Nixpkgs repository:
$ nix-env --file https://github.com/NixOS/nixpkgs/archive/master.tar.gz --query --available
That's the whole page bestie! ๐
source/version: nix-env --query(1). the date is stamped in the footer too, go give it a peek. you ate that. periodt. ๐โจ
๐ฆ 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