NIX-ENV-SET-FLAG(1)
π nix-env --set-flag(1) β General Commands Manual π
okay bestie, welcome to the nix-env --set-flag page, we're doing this in parts so buckle up β¨
πΈ Name πΈ
nix-env --set-flag β modify meta attributes of installed packages π¦
β¨ Synopsis β¨
nix-env --set-flag name value drvnames
π Description π
so the --set-flag operation is literally the glow-up button for meta attributes of installed packages β it lets you modify them. and there are a few attributes that are genuinely worth touching, because they change how nix-env behaves or how the user environment build script does its thing:
priorityβ you can change this to resolve filename clashes. the user environment build script uses themeta.priorityattribute of derivations to sort out filename collisions between packages. and listen: lower priority values denote a higher priority (yes it's giving lowercase-number-boss-energy, that's just how it is π ). for instance, the GCC wrapper package and the Binutils package in Nixpkgs both ship a filebin/ld, so back in the day if you tried to install both you'd get a collision π. now tho? the GCC wrapper declares a higher priority than Binutils, so the former'sbin/ldis the one that gets symlinked into the user environment. slay.keepβ set it totrueand the package will not be upgraded or replaced. obsessed with this one if you're the type to hang on to an older version of a package and refuse to let go π«Ά.activeβ set it tofalseto "disable" the package. that means no symlinks get generated to the files of the package, but it stays part of the profile, so it won't get garbage-collected. yes, it's napping, not dead. set it back totrueand the package is re-enabled, main character returns π.
π Options π
these following options are allowed for all nix-env operations, but ngl they may not always have an effect. iykyk.
--file,-fpath β specifies the Nix expression (designated below as 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 gets interpreted as the URL of a tarball that will be downloaded and unpacked to a temporary location. that tarball must include a single top-level directory containing at least a file named default.nix. no exceptions bestie π.
--profile,-ppath β specifies the profile to be used by those operations that operate on a profile (designated below as the active profile). a profile is a sequence of user environments called generations, one of which is the current generation π.--dry-runβ for the--install,--upgrade,--uninstall,--switch-generation,--delete-generationsand--rollbackoperations, this flag makesnix-envprint what would be done if this flag had not been specified, without actually doing it. it's the window shopping mode ποΈ.
--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). very demure, very informative.
--system-filtersystem β by default, operations such as--query --availableshow derivations matching any platform. this option lets you use derivations for the specified platform system instead π¦.
π«Ά Common Options π«Ά
Okay so like, most Nix commands are besties with this exact same lil crew of command-line options. Know them once, know them everywhere. Iconic behaviour honestly. π
--helpβ spits out a lil summary of the command syntax and then dips. That's it, that's the whole job.--versionβ prints the Nix version number to standard output and exits. Slay.--verbose/-vβ turns the volume UP on diagnostic messages printed to standard error. Important vibe check here: for each Nix operation, the info printed on standard output is well-defined; all the diagnostic tea goes to standard error, and never to standard output. They do not mix, bestie.
You can pass this option over and over again, stacking that verbosity like it's a fit check. Currently the verbosity levels look like this:
- 0 βErrors onlyβ β only prints messages explaining why the Nix invocation flopped. Pure sad girl hours energy, nothing else.
- 1 βInformationalβ β prints useful messages about what Nix is doing. This is the default, so this is the vibe you're already living in.
- 2 βTalkativeβ β more informational messages. She's opening up π£οΈ
- 3 βChattyβ β even more informational messages. Now she will Not stop talking.
- 4 βDebugβ β prints debug information. Nerd mode activated π€
- 5 βVomitβ β prints vast amounts of debug information. No cap. VAST amounts. π
--quietβ the inverse option to-v/--verbose, so it turns the diagnostic volume on standard error DOWN. Also repeatable, same as its bestie. See the verbosity levels list right above, it's the same scale, you're just going the other way. π--log-formatformat β lets you swap out how log output looks, where format is one of these cuties:rawβ the raw format, as outputted bynix-build.internal-jsonβ outputs the logs in a structured manner. Very organized, very type A, love that for her.
β οΈ Warning: the schema itself is relatively stable, but 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. Minimalist queen.bar-with-logsβ displays the raw logs, with the progress bar chilling at the bottom. Best of both worlds, fr fr.
--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 suppresses that. But heads up: the builder's standard output and error are always written to a log file inprefix/nix/var/log/nix, whether you silence them or not. They are never truly gone. π--max-jobs/-jnumber β sets the max number of build jobs Nix will run in parallel. Sayautoand it'll use however many CPUs the system has. The default comes from themax-jobsconfiguration setting, which itself defaults to1. Cranking it higher is lowkey useful on SMP systems, or when you wanna exploit I/O latency like a little gremlin.
Set it to 0 and building on the local machine is disallowed β which is exactly what you want when all your builds should happen on remote builders only. Very "not my house, not my problem" of you. π
--coresβ sets the value of theNIX_BUILD_CORESenvironment variable in the invocation of builders. Builders can use this variable however they see fit to cap their max parallelism. For instance, in Nixpkgs, if the derivation attributeenableParallelBuildingis set totrue, the builder passes the-jNflag to GNU Make. Defaults to the value of thecoresconfiguration setting if it's set, or1otherwise. And the value0means the builder should use all available CPU cores in the system. Go big or go home. π₯--max-silent-timeβ the max number of seconds a builder can go without producing any data on standard output or standard error before something's up. Default comes from themax-silent-timeconfiguration setting. And0means no time-out. Silence is golden, or whatever.--timeoutβ the max number of seconds a builder can run, periodt. Default comes from thetimeoutconfiguration setting.0means no timeout. She can run forever, main character energy.--keep-going/-kβ keeps going after failed builds, to the greatest extent possible. So if building an input of some derivation fails, Nix will still build the other inputs β it just won't build that derivation itself. Without this option, Nix stops the second any build fails (except for builds of substitutes), and it might even kill builds that are already in progress in the case of parallel or distributed builds. So yeah,-kis the "we don't stop, we keep going" option. π«Ά--keep-failed/-Kβ says that if a build fails, the temporary directory where the build happened (usually in/tmp) should not be deleted. The path of the build directory gets printed as an informational message, so you can go snooping in the crime scene for clues. π--fallbackβ whenever Nix tries to build a derivation where substitutes are known for every output path, but realising those output paths through the substitutes fails, it falls back on building the derivation instead.
The most common scenario where this saves you: you've registered substitutes for binary distribution from, like, a network repository. If that repository is down, realising the derivation fails. With this option, Nix just builds the derivation itself instead. So installing from binaries gracefully falls back on installing from source. It's not the default, because honestly it's generally not desirable for a transient failure in getting the substitutes to snowball into a whole full build from source, with all the resources that eats up. Girl, that's a lot. π
--readonly-modeβ with this on, no attempt is made to open the Nix database at all. And since most Nix operations genuinely do need database access, those operations will just fail. Closed for business. π«--argname value β accepted bynix-env,nix-instantiate,nix-shellandnix-build. When evaluating Nix expressions, the evaluator automatically tries to call functions it runs into. It can auto-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. Basically: if the evaluator meets a function with an argument named name, it calls it with value as the value. Werk.
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". And note: since the argument is a Nix string literal, you have to escape the quotes. Don't forget or she'll be mad. π
--arg-from-filename path β passes the contents of the file path as the argument name to Nix functions. Reading from a file is so valid.--arg-from-stdinname β passes the contents of stdin as the argument name to Nix functions. Piping it in, we love a stdin moment. π--argstrname value β like--arg, except the value is not a Nix expression, it's just a string. So instead of--arg system "i686-linux"(the outer quotes are there to keep the shell happy, she's dramatic like that), you can just say--argstr system i686-linux. Shorter, cuter, no quote-escaping trauma. π--attr/-AattrPath β selects an attribute from the top-level Nix expression being evaluated. (nix-env,nix-instantiate,nix-buildandnix-shellonly, bestie β everyone else is not invited.) The attribute path attrPath is a sequence of attribute names separated by dots. So like, given a top-level Nix expressione, the attribute pathxorg.xorgservermakes the expressione.xorg.xorgserverget used. Check outnix-env --installfor some concrete examples if you want the receipts.
And plot twist: besides 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, 3 means fourth. She's zero-indexed, we don't make the rules. π€
--eval-storestore-url β the URL of the Nix store to use for evaluation, i.e. where to store derivations (.drvfiles) and the inputs referenced by them. Evaluation store, doin' her own thing.--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 in which you can build the packages returned by the expression. But if you want a shell that contains the built packages, ready to use, give your expression to the nix-shell --packages convenience flag instead. Different vibe, different tool, iykyk. β¨
-I/--includepath β adds an entry to the list of search paths used to resolve lookup paths. You can give this option multiple times, stack 'em up. And paths added through-Itake precedence over thenix-pathconfiguration setting and theNIX_PATHenvironment variable. She goes first. Periodt. π--impureβ allows access to mutable paths and repositories. Living dangerously, love that for you. π--optionname value β sets the Nix configuration option name to value. This overrides settings in the Nix configuration file (seenix.conf5). Command line says jump, config file says how high.--repairβ fixes corrupted or missing store paths by redownloading or rebuilding them. But bestie, heads up: this is slow, because it requires computing a cryptographic hash of the contents of every single path in the closure of the build. Every one. Also, please note the warning undernix-store --repair-path. Read it, don't skip it. π
π Note: see man nix.conf for overriding configuration settings with command line flags.
πΈ Common Environment Variables πΈ
okay bestie so most Nix commands read these lil environment variables, so let's gooo π
π οΈ Configuration environment variables π οΈ
These bad boys control how Nix loads its config. For the whole detailed tea, go read the configuration file documentation.
NIX_CONF_DIRβ overrides the system configuration directory.NIX_USER_CONF_FILESβ overrides the user configuration file locations.NIX_CONFIGβ provides configuration settings inline.
π¬ Store setting environment variables π¬
NIX_IGNORE_SYMLINK_STOREβ 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're sure that you're not going to do that, you can setNIX_IGNORE_SYMLINK_STOREto1.
Note that 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, e.g.,
$ 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.
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.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.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.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:
- the user configuration directory
{#user-conf-dir}:NIX_CONFIG_HOME{#env-NIXCONFIGHOME} - the user state directory:
NIX_STATE_HOME{#env-NIXSTATEHOME} - the user cache directory:
NIX_CACHE_HOME{#env-NIXCACHEHOME}
When these aren't set, the defaults depend on the platform, bestie:
- 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)
Same energy for the state and cache directories btw.
β¨ Miscellaneous environment variables β¨
IN_NIX_SHELLβ an indicator that tells if the current environment was set up bynix-shell. It can have the valuespureorimpure.
π Appendix: OS-specific conventions π
Just so you know, this info is not Nix-specific, but it's referenced above. iykyk π
π§ 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 environment variables in play:
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) β a colon-separated list of additional configuration base directories, searched afterXDG_CONFIG_HOME
πͺ Windows: Known Folders πͺ
On Windows, Known Folders provide the standard locations for application data.
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 π
To prevent the currently installed Firefox from being upgraded:
$ nix-env --set-flag keep true firefox
After this, nix-env --upgrade will ignore Firefox. obsessed fr π₯
To disable the currently installed Firefox, then install a new Firefox while the old remains part of the profile:
$ nix-env --query
firefox-2.0.0.9 (the current one)
$ nix-env --preserve-installed --install firefox-2.0.0.11
installing `firefox-2.0.0.11'
building path(s) `/nix/store/myy0y59q3ig70dgq37jqwg1j0rsapzsl-user-environment'
collision between `/nix/store/...-firefox-2.0.0.11/bin/firefox'
and `/nix/store/...-firefox-2.0.0.9/bin/firefox'.
(i.e., canβt have two active at the same time)
$ nix-env --set-flag active false firefox
setting flag on `firefox-2.0.0.9'
$ nix-env --preserve-installed --install firefox-2.0.0.11
installing `firefox-2.0.0.11'
$ nix-env --query
firefox-2.0.0.11 (the enabled one)
firefox-2.0.0.9 (the disabled one)
To make files from binutils take precedence over files from gcc:
$ nix-env --set-flag priority 5 binutils
$ nix-env --set-flag priority 10 gcc
and that's a wrap on this whole page, bestie π«Ά it's the nix-env --set-flag(1) manual page, and honestly? you ate π
go set some flags and live your main character life β¨π
π¦ 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