NIX-STORE-PRINT-ENV(1)
π nix-store --print-env β from the General Commands Manual (girl help, it's a nix-store(1) situation) π
β¨ NAME β¨
nix-store --print-env β bestie, it prints out the build environment of a derivation π
π¦ SYNOPSIS π¦
nix-store --print-env drvpath
πΈ DESCRIPTION πΈ
okay so. The --print-env operation prints out the environment of a derivation in a format that can be evaluated by a shell. No cap, it's genuinely that simple β you hand it a derivation path, it hands you environment variables back, and they're shell-eval-able. slay.
And the plot twist π«Ά: the command line arguments of the builder get placed in the variable _args.
π OPTIONS π
These following options are allowed for all nix-store operations, but heads up β they may not always have an effect. it's giving "available everywhere, does something sometimes" π
--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. Plus, 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. iconic behaviour honestly π
β οΈ 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 don't even 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). the way it just counts up π
periodt.
β¦part 1 of 3, bestie, keep scrolling π
β¨ COMMON OPTIONS β¨
okay so bestie, here's the tea β β like most Nix commands speak this exact same flag dialect, so once you learn these you've basically unlocked the whole squad. let's go π
--helpβ prints a lil summary of the command syntax and then dips out. that's it, that's the whole move β¨--versionβ spits the Nix version number onto standard output and exits. iconic, no notes π--verbose/-vβ turns the volume UP on those diagnostic messages printed to standard error. here's the thing that matters: for every Nix operation, whatever goes to standard output is well-defined, and any diagnostic chatter goes to standard error, never to standard output. periodt.
you can drop this flag as many times as you want, and rn these are the verbosity levels that exist:
- 0 "Errors only" β only prints messages telling you why the Nix invocation failed. tough love π
- 1 "Informational" β prints useful messages about what Nix is actually doing. this one is the default π«Ά
- 2 "Talkative" β more informational messages. she's chatty now.
- 3 "Chatty" β even more informational messages. okay she's really talking.
- 4 "Debug" β prints debug info. tech support mode π₯
- 5 "Vomit" β prints a vast amount of debug info. the name is not a joke bestie, it's giving firehose π
--quietβ turns the volume DOWN on diagnostic messages to standard error. it's literally the inverse of-v/--verbose.
this one can also be given multiple times, and yeah, same verbosity level list as above π
--log-formatformat β use this to switch up how the log output gets formatted, where format is one of these:rawβ the raw format, exactly as outputted bynix-build.internal-jsonβ outputs the logs in a structured manner.
β οΈ Warning β the schema itself is relatively stable, but the format of the error-messages (namely of the msg-field) can change between releases. so like... don't hardcode your whole personality around it, k? π
barβ only shows a progress bar during the builds. minimal queen πbar-with-logsβ shows the raw logs, with the progress bar chilling at the bottom.
--no-build-output/-Qβ by default, anything builders write to standard output and standard error gets echoed to the Nix command's standard error. this option suppresses that behaviour. important heads up tho: the builder's standard output and error are always written to a log file inprefix/nix/var/log/nix, no matter what π«Ά--max-jobs/-jnumber β sets the max number of build jobs Nix will run in parallel to number. sayautoif you want it to use the number of CPUs on 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 β and that's <highkey>genuinely useful</highkey> when you want builds to happen only on remote builders π
--coresβ sets the value of theNIX_BUILD_CORESenvironment variable in the invocation of builders. builders can use that variable however they like to control their 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. and the value0means the builder should go feral and use all available CPU cores in 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. default comes from themax-silent-timeconfiguration setting.0means no time-out π--timeoutβ sets the max number of seconds a builder can run. default comes from thetimeoutconfiguration setting.0means no timeout.--keep-going/-kβ keeps going in case of failed builds, to the greatest extent possible. so like, 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 (that's the parallel or distributed builds case btw) π--keep-failed/-Kβ says that in case of a build failure, the temporary directory (usually in/tmp) where the build happens should not be deleted. the path of the build directory gets printed as an informational message, so you can go poke around π΅οΈβοΈ--fallbackβ whenever Nix tries to build a derivation where 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 saves you: you've registered substitutes to do binary distribution from, say, a network repository. if that repository is down, realising the derivation will fail. with this option, Nix builds the derivation instead β so installation from binaries falls back on installation from source β¨ this isn't the default because it's generally not desirable for a transient failure in obtaining substitutes to lead to a full build from source (plus all the resource consumption that comes 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 straight up fail π--argname value β accepted bynix-env,nix-instantiate,nix-shellandnix-build. when evaluating Nix expressions, the evaluator will automatically try to call functions that it encounters. it can automatically call functions where every argument has a default value, like{ argName ? defaultValue }: ....
with --arg, you can also call functions that have arguments without a default value (or override a default value). so if the evaluator hits a function with an argument named name, it calls it with 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 (like 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". (heads up: since the argument is a Nix string literal, you gotta escape the quotes π€)
--arg-from-filename path β passes the contents of the file path as the argument name to Nix functions π--arg-from-stdinname β passes the contents of stdin as the argument name to Nix functions π«Ά--argstrname value β same energy as--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 there to keep your shell happy), you can say--argstr system i686-linux. way less escaping drama β¨--attr/-AattrPath β 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 example, given a top-level Nix expressione, the attribute pathxorg.xorgserverwould make the expressione.xorg.xorgserverget used. check outnix-env --installfor some concrete examples π
and it's not just names β you can specify array indices too. 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 π’
--eval-storestore-url β the URL of the Nix store to use for evaluation, i.e. where to store derivations (.drvfiles) and inputs referenced by them.--expr/-Eβ interprets the command line arguments as a list of Nix expressions to be parsed and evaluated, instead of 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 where 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/--includepath β adds an entry to the list of search paths used to resolve lookup paths. this option can be given multiple times.
paths added via -I take precedence over the nix-path configuration setting and the NIX_PATH environment variable. she goes first, periodt π
--impureβ allows access to mutable paths and repositories. chaos mode unlocked π--optionname 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 has to compute a cryptographic hash of the contents of every path in the closure of the build. also go read the warning undernix-store --repair-pathπ¨
π Note β see man nix.conf for overriding configuration settings with command line flags.
πΈ Common Environment Variables πΈ
Okay bestie, these are the env vars that basically every Nix command out there knows how to read. Most Nix commands interpret the following environment variables. π«Ά
βοΈ Configuration environment variables
These ones decide how Nix loads its configuration in the first place. See the configuration file documentation for full details, iykyk.
NIX_CONF_DIRβ overrides the system configuration directory.NIX_USER_CONF_FILESβ overrides the user configuration file locations.NIX_CONFIGβ provides configuration settings inline. Yes, right there in the variable. Iconic.
π¬ Store setting environment variables
NIX_IGNORE_SYMLINK_STOREβ ngl this one's got lore. Normally, the Nix store directory (typically/nix/store) is not allowed to contain any symlink components. This is to prevent βimpureβ builds. Builders sometimes βcanonicaliseβ paths by resolving all symlink components. Thus, builds on different machines (with/nix/storeresolving to different locations) could yield different results. This is generally not a problem, except when builds are deployed to machines where/nix/storeresolves differently. If you are sure that youβre not going to do that, you can setNIX_IGNORE_SYMLINK_STOREto1.
Heads up bestie β if youβre symlinking the Nix store so that you can put it on another file system than the root file system, on Linux youβre better off using bind mount points, like this:
$ mkdir /nix
$ mount -o bind /mnt/otherdisk/nix /nix
Consult the mount 8 manual page for 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 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. (Same trio as above, they stay meddling β¨)
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β uses 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. Numbers, but make it β¨diagnosticβ¨.NIX_COUNT_CALLSβ if set to1, Nix will print how often functions were called during Nix expression evaluation. This is useful for profiling your Nix expressions. Very main character of your expressions, honestly.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 to384 MiB. Setting it to a low value reduces memory consumption, but will increase runtime due to the overhead of garbage collection. Pick your fighter. π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. Fr fr. π
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:
NIX_CONFIG_HOME - user state directory:
NIX_STATE_HOME - user cache directory:
NIX_CACHE_HOME
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. Slay, glow-up era. π
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. Same rule, three times, consistency queen. π
π Miscellaneous environment variables
IN_NIX_SHELLβ indicator that tells if the current environment was set up bynix-shell. It can have the valuespureorimpure. Vibe check on your shell, basically.
π Appendix: OS-specific conventions
This information is not Nix-specific, but is referenced above. So like, general OS lore. π§
π§ 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(default~/.config)XDG_STATE_HOME(default~/.local/state)XDG_CACHE_HOME(default~/.cache)XDG_CONFIG_DIRS(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%β per-user roaming application data%LOCALAPPDATA%β per-user local application data%PROGRAMDATA%β system-wide application data
π Example
Here's the whole thing in action, bestie:
$ nix-store --print-env $(nix-instantiate '<nixpkgs>' -A firefox)
β¦
export src; src='/nix/store/plpj7qrwcz94z2psh6fchsi7s8yihc7k-firefox-12.0.source.tar.bz2'
export stdenv; stdenv='/nix/store/7c8asx3yfrg5dg1gzhzyq2236zfgibnn-stdenv'
export system; system='x86_64-linux'
export _args; _args='-e /nix/store/9krlzvny65gdc8s7kpb6lkx8cd02c25c-default-builder.sh'
And that's a wrap on the whole page, gorgeous. π«Ά The little footer at the bottom just says nix-store --print-env(1) β that's the source/version and date line, holding it down quietly at the end of the manpage like the icon it is. Go forth and print-env responsibly. 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