NIX-ENV-SWITCH-GENERATION(1)
okay so bestie, welcome to the manual for nix-env --...-generation(1) โ the part where we talk about switching generations like it's a glow-up for your profile ๐
โจ
๐ NAME ๐
nix-env --switch-generation โ set your user environment to a given profile generation. periodt.
๐ธ SYNOPSIS ๐ธ
nix-env {--switch-generation | -G} generation
๐ฆ DESCRIPTION ๐ฆ
This operation makes generation number generation the current generation of the active profile. That is, if the profile is the path to the active profile, then the symlink profile is made to point to profile-generation-link, which is in turn a symlink to the actual user environment in the Nix store. it's giving symlink inception, but make it functional ๐
Switching will fail if the specified generation does not exist. so don't come for a generation that isn't there, bestie โ it will not slay.
๐ OPTIONS ๐
The following options are allowed for all nix-env operations, but 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 withhttp://orhttps://, it is 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 nameddefault.nix. no cap.--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. so it's like a little family tree of your setups ๐ณโจ--dry-runโ For the--install,--upgrade,--uninstall,--switch-generation,--delete-generationsand--rollbackoperations, this flag will causenix-envto print what would be done if this flag had not been specified, without actually doing it.--dry-runalso prints out which paths will be substituted (i.e., downloaded) and which paths will be built from source (because no substitute is available). basically it's the "look but don't touch" of nix-env ๐ซถ--system-filtersystem โ By default, operations such as--query --availableshow derivations matching any platform. This option allows you to use derivations for the specified platform system. so if you're on a specific vibe of machine, you can filter for it ๐
okay but wait โ there's more manual to devour, bestie. part 2 is coming, so don't go anywhere ๐โจ
โจ Common Options โจ
Okay bestie, listen up ๐ โ most Nix commands take these command-line options, and they're kinda the shared wardrobe every command is wearing. So if you know these, you know, like, half the tooling already. Iconic.
--helpโ prints out a lil summary of the command syntax and then dips (exits). Baby's first flag ๐ผ--versionโ prints the Nix version number on standard output and exits. That's it, that's the whole job ๐--verbose/-vโ turns up the volume on diagnostic messages printed to standard error ๐ฅ. For every Nix operation, the stuff on standard output is well-defined; any diagnostic tea gets spilled on standard error, never on standard output. You can pass this over and over again to keep stacking. Right now these verbosity levels exist:- 0 โErrors onlyโ
Only prints messages explaining why the Nix invocation failed. Ngl, brutal but honest ๐
- 1 โInformationalโ
Prints useful messages about what Nix is doing. This is the default ๐ซถ
- 2 โTalkativeโ
Prints more informational messages.
- 3 โChattyโ
Prints even more informational messages. She's yapping, and we love her for it โจ
- 4 โDebugโ
Prints debug information.
- 5 โVomitโ
Prints vast amounts of debug information. No, literally, "Vomit." The name is real and I did not make that up ๐ซฃ
--quietโ turns the volume back down on diagnostic messages printed to standard error. It's the inverse option to-v/--verbose, and yeah, you can pass it repeatedly too. Same verbosity levels list as above, just going the other way ๐--log-formatformat โ lets you change the output of the log format, where format is one of:raw
This is the raw format, 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 like, don't hard-depend on it, bestie ๐ญ
bar
Only displays a progress bar during the builds.
bar-with-logs
Displays the raw logs, with the progress bar at the bottom.
--no-build-output/-Qโ by default, whatever the builders write to standard output and standard error gets echoed to the Nix command's standard error. This option suppresses that behaviour. Heads up though: the builder's standard output and error are always written to a log file inprefix/nix/var/log/nix. So nothing's lost, she's just being quiet ๐- *
--max-jobs/-j*number โ sets the max number of build jobs Nix will do in parallel. Sayautoand it'll use the number of CPUs in 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 โ which is exactly what you want when you only ever wanna build 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 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 ๐ฅ๐ฅ--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 really is golden, apparently โณ--timeoutโ sets the max number of seconds a builder can run. Default is specified by thetimeoutconfiguration setting.0means no timeout. Give her all the time she needs, queen โฐ--keep-going/-kโ keeps going when builds fail, 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 โ which, oof, in the case of parallel or distributed builds ๐--keep-failed/-Kโ says that in case of a build failure, the temporary directory (usually in/tmp) where the build took place should not be deleted. The path of the build directory gets printed as an informational message. Perfect for going in there and seeing what went wrong forensically ๐๐ต๏ธ--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, fall back on building the derivation. The most common scenario where this is a whole vibe is when you've registered substitutes to do binary distribution from, like, a network repository. If the repo is down, the realisation of the derivation will fail โ but with this option, Nix builds the derivation instead. So installation from binaries falls back on installation from source ๐ซถ
It is not the default, since it's generally not desirable for a transient failure in obtaining substitutes to lead to a full build from source (and all the related resource consumption that comes with it). So like, use it with intention, bestie โจ
--readonly-modeโ no attempt is made to open the Nix database. Most Nix operations do need database access, so those operations will fail. It's giving "look don't touch" ๐--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 (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.
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 donix-env --install --attr pkgname), the function will be called automatically using the valuebuiltins.currentSystemfor thesystemargument. 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-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๐--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 instance, given a top-level Nix expression e, the attribute pathxorg.xorgserverwould cause the expressione.xorg.xorgserverto be used. Check outnix-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 ๐
--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โ 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-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 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 may be given multiple times. Paths added through-Itake precedence over thenix-pathconfiguration setting and theNIX_PATHenvironment variable. She said "I go first" ๐--impureโ allows access to mutable paths and repositories. Chaotic energy, but make it on purpose ๐ช๏ธ--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 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 ๐ฆ
๐ Common Environment Variables ๐
Bestie, listen. Most Nix commands read these environment variables, so likeโฆ get comfy. ๐ซถ
โ๏ธ Configuration environment variables
These ones control how Nix loads up its configuration. Full deets live in the configuration file documentation, but here's the rundown:
NIX_CONF_DIRโ overrides the system configuration directory. ๐NIX_USER_CONF_FILESโ overrides where the user configuration files are.NIX_CONFIGโ hands you configuration settings inline, 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 contain any symlink components, and that rule exists to prevent "impure" builds. Here's why: builders sometimes "canonicalise" paths by resolving all the symlink components, so builds on different machines (where/nix/storeresolves to different places) could totally give you different results ๐ญ. Usually that's not a problem โ except when builds get deployed to machines where/nix/storeresolves differently. So if you are sure you're not gonna do that, setNIX_IGNORE_SYMLINK_STOREto1.
Heads up though: if you're symlinking the Nix store just so you can park it on a different filesystem than the root filesystem, on Linux you're way better off using bind mount points, like this:
$ mkdir /nix
$ mount -o bind /mnt/otherdisk/nix /nix
Go peek at the mount 8 manual page for the details. no cap. ๐ฆ
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.
See the Store Types chapter โ every store has a store setting that links back to this as its default.
NIX_LOG_DIRโ overrides where the Nix log directory lives. On Unix, the default is/nix/var/log/nix, set at compile time by thelog-dirbuild option. On Windows, again, 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 all have per-store settings that override this. ๐
NIX_STATE_DIRโ overrides where the Nix state directory lives. On Unix, the default is${localstatedir}/nix, wherelocalstatediris a compile-time build option that defaults to/nix/var. On Windows, no compile-time setting; the default is%PROGRAMDATA%\nix\state, determined at runtime using the%PROGRAMDATA%Known Folder.
Same situation as above โ 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 todaemon-socket/socketinside the state directory (seeNIX_STATE_DIR).
See the Local Daemon Store documentation for the full story on how the socket path gets resolved. ๐ธ
TMPDIRโ use this directory to stash temporary files. Specifically, that includes temporary build directories, which can eat up substantial amounts of disk space. The default is/tmp.NIX_REMOTEโ overrides the store setting. that's it, that's the whole vibe.
๐งฎ Nix language evaluator settings
NIX_SHOW_STATSโ set it to1and Nix prints out some evaluation statistics, like how many values got allocated. cute little numbers โจNIX_COUNT_CALLSโ set it to1and Nix prints how often functions were called while evaluating Nix expressions. Super useful for profiling your Nix expressions.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. Setting it low reduces memory consumption, but it'll increase runtime because garbage collection overhead goes up. tradeoffs, bestie ๐ญ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 where those directories go:
[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 gets resolved like this:
$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. ๐
๐ 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
This info isn't Nix-specific at all, but it gets referenced up above, so here it is anyway.
Unix: XDG Base Directories
The XDG Base Directory Specification defines standard locations for user-specific configuration, state, and cache files on Unix systems.
The environment variables in play are:
[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 extra configuration base directories, searched afterXDG_CONFIG_HOME
Windows: Known Folders
On Windows, Known Folders provide the 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
$ nix-env --switch-generation 42
switching from generation 50 to 42
and that's the whole page, bestie!! ๐ the footer at the bottom just says nix-env --...-generation(1) โ no date stamp, just her name in lights, from the General Commands Manual. go forth and switch generations, you absolute icon ๐๐
๐ฆ 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