NIX-ENV-DELETE-GENERATIONS(1)
nix-env --delete-generations π
okay bestie, you found the nix-env --delete-generations page in the General Commands Manual and honestly? it's giving "profile glow-up". this is the one that deletes profile generations. no cap. let's get into it β¨
β¨ NAME β¨
nix-env --delete-generations β delete profile generations ποΈπ
β¨ SYNOPSIS β¨
nix-env --delete-generations generations
β¨ DESCRIPTION β¨
so basically this operation deletes the specified generations of the current profile. that's the whole vibe. periodt.
and generations can be one of the following cuties:
<number>...β a list of generation numbers, each one a separate command-line argument. this deletes exactly the profile generations you name by their generation number. but heads up: deleting the current generation is not allowed. absolutely not. the current one is the main character and stays. π ββοΈ- the special value
oldβ deletes all generations except the current one. all of them. yes.
β οΈ WARNING β οΈ older and newer generations will be deleted by this operation. not just the older ones. bestie, read this part twice. one might expect this to just delete older generations than the current one, but that is only true if the current generation is also the latest. because you can roll back to a previous generation, it is possible to have generations newer than the current one. and those will also be deleted. π so like. vibe check before you run this.
<number>dβ the last number days. example:30d. deletes all generations created more than number days ago, except the most recent one of them. this is the cute one because it lets you roll back to generations that were available within the specified period. π¦+<number>β the last number generations up to the present. example:+5. keeps the last number generations, along with any newer than current. π
lowkey important: periodically deleting old generations is important to make garbage collection effective. why? because profiles are also garbage collection roots β any store object reachable from a profile is "alive" and ineligible for deletion. so like, if you never clean up, your store just keeps growing forever and the garbage collector literally cannot touch it. the way that a profile keeps everything alive... it's giving hoarder energy. π clean up your generations and the GC can actually do its job. iykyk.
β¨ OPTIONS β¨
these following options are allowed for all nix-env operations, but ngl they may not always have an effect. depends on the operation bestie. π
--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. ποΈ
and here's the fun part: if the argument starts with http:// or https://, 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 named default.nix. one directory, got it? not zero, not five. β¨
--profile,-ppath β specifies the profile to be used by those operations that operate on a profile (designated below as the active profile). and what even is a profile? a profile is a sequence of user environments called generations, one of which is the current generation. so yes, that's the thing we've been deleting bits of this whole time. we're so back. π--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. the responsible queen behavior. π«Ά
--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 you get the full tea before committing. π
--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 you can be picky. as you should be. π
πΈ part 1 done, and there's more coming bestie β don't go anywhere πΈ
π¦ Common Options π¦
okay bestie, here's the tea π most Nix commands accept the same little squad of command-line options, so learn these once and you've basically unlocked the whole family. no cap.
--helpβ prints out a summary of the command syntax and then dips out immediately. exits right after.--versionβ prints out the Nix version number on standard output and exits. that's it, that's the whole vibe.--verbose/-vβ cranks up the level of verbosity for the diagnostic messages printed on standard error. here's the important bit: for each Nix operation, the info printed on standard output is well-defined, and any diagnostic info goes to standard error, never to standard output. β¨
This option may be specified repeatedly. Currently, the following verbosity levels exist:
0"Errors only" β only prints messages explaining why the Nix invocation failed. it's giving silent treatment.1"Informational" β prints useful messages about what Nix is doing. this is the default, bestie π2"Talkative" β prints more informational messages.3"Chatty" β prints even more informational messages.4"Debug" β prints debug information.5"Vomit" β prints vast amounts of debug information. literally a firehose π
--quietβ turns the verbosity of diagnostic messages printed on standard error down. it's the inverse option to-v/--verbose.
This option may be specified repeatedly. See the verbosity levels list above. π
--log-formatformat β use this to change the output of the log format. format is one of:rawβ this is 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 like... don't hardcode-parsing it and then act surprised, iykyk.
barβ only display a progress bar during the builds.bar-with-logsβ display the raw logs, with the progress bar at the bottom.
--no-build-output/-Qβ by default, the 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, so nothing's actually lost, we're just being quiet about it π€«--max-jobs/-jnumber β sets the maximum number of build jobs that Nix will perform in parallel to the specified number. specifyautoto 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. multitasking icon behaviour π
Setting it to 0 disallows building on the local machine, which is useful 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 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 that the builder should use all available CPU cores in the system. go girl give us everything π₯--max-silent-timeβ sets the maximum number of seconds that 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.--timeoutβ sets the maximum number of seconds that 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). resilient queen energy π«Ά--keep-failed/-Kβ specifies that in case of a build failure, the temporary directory (usually in/tmp) in which the build takes place should not be deleted. the path of the build directory is printed as an informational message. perfect for when you wanna snoop on the aftermath π--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 in which 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). like, imagine rebuilding the whole world because wifi blinked. no thank you π
--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. it's giving look-don't-touch.--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. shell girlies know π)
--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. way less escaping drama, obsessed π--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 bestie, counting starts at zero, it's giving programmer brain π§ )
--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 contain 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. main character privilege, honestly π
--impureβ allow access to mutable paths and repositories.--optionname value β set the Nix configuration option name to value. this overrides settings in the Nix configuration file (seenix.conf5).--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. π it's giving "worth it but bring snacks".
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 β¨
Okay bestie, so like most Nix commands out here read these environment variables π β they're the shared vocabulary, the group chat everyone's in.
π Configuration environment variables π
These ones decide how Nix loads its config. The configuration file docs have the full tea, but here's the short version:
NIX_CONF_DIRβ overrides where the system configuration directory lives.NIX_USER_CONF_FILESβ overrides where the user configuration files live.NIX_CONFIGβ lets you hand Nix configuration settings inline. no file, just vibes β¨
π Store setting environment variables π
NIX_IGNORE_SYMLINK_STOREβ ngL, normally the Nix store directory (usually/nix/store) is not allowed to contain any symlink components, because that would let "impure" builds sneak in π. Here's the why: builders sometimes "canonicalise" paths by resolving every symlink component. So builds on different machines (where/nix/storeresolves to different places) could hand you different results. Usually that's not a problem β except when builds get deployed to machines where/nix/storeresolves differently. If you're sure that's not your situation, setNIX_IGNORE_SYMLINK_STOREto1.
π«Ά little tip from the original: if you're symlinking the Nix store just to put it on a different file system than the root file system, on Linux you're better off using bind mount points, like:
$ mkdir /nix
$ mount -o bind /mnt/otherdisk/nix /nix
And go read the mount 8 manual page for the details, periodt.
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's no compile-time setting at all; the default is
%PROGRAMDATA%\nix\store, determined at runtime using the%PROGRAMDATA%Known Folder.
- On Unix, the default is
See the Store Types chapter β 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; the default is
%PROGRAMDATA%\nix\log, determined at runtime using the%PROGRAMDATA%Known Folder.
- On Unix, the default is
The Local Store, the Local Daemon Store, and the Experimental SSH Store with filesystem mounted each have per-store settings that override this one π
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, no compile-time setting; the default is
%PROGRAMDATA%\nix\state, determined at runtime using the%PROGRAMDATA%Known Folder.
- On Unix, the default is
Same deal here: the Local Store, Local Daemon Store, and Experimental SSH Store with filesystem mounted have per-store settings that override it π
NIX_DAEMON_SOCKET_PATHβ overrides the path to the Unix domain socket used to talk to the Nix daemon. Defaults todaemon-socket/socketinside the state directory (seeNIX_STATE_DIR). Check the Local Daemon Store docs for the full story on how the socket path gets resolved πTMPDIRβ use this directory to store temporary files. Specifically, that includes temporary build directories, which can eat up a substantial amount of disk space β be so fr about your disk, bestie π. Default is/tmp.NIX_REMOTEβ overrides the store setting.
π§ Nix language evaluator settings π§
NIX_SHOW_STATSβ if you set it to1, Nix prints some evaluation statistics, like how many values got allocated. numbers go brrr πNIX_COUNT_CALLSβ if you set it to1, Nix prints how often functions were called while evaluating Nix expressions. perfect for profiling your Nix expressions, iykyk.GC_INITIAL_HEAP_SIZEβ if Nix was configured to use the Boehm garbage collector, this sets the initial heap size in bytes. Defaults to384 MiB. Setting it low means less memory consumption but a longer runtime, thanks to garbage collection overhead. trade-offs, the way that life works πNIX_PATHβ a colon-separated list of search path entries used to resolve lookup paths. This environment variable overrides the value of thenix-pathconfiguration setting. You can extend it with the-Ioption.
Example β okay love this for us:
$ 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, because of course it does β main character energy β¨. These environment variables override where those directories live:
[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 (like nix-env, nix-channel) use dotfiles in $HOME instead of these directories β unless use-xdg-base-directories is enabled. New Nix commands (the experimental ones) use the proper directories by default. glow up π¦
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)
And likewise for the state and cache directories. consistent queen π
π 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, but it got referenced up above, so here it is.
βοΈ 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) β a 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. 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 π₯
Time for the actual receipts, bestie. these are the moments.
βοΈ Delete explicit generation numbers
$ nix-env --delete-generations 3 4 8
Deletes the generations numbered 3, 4, and 8 β as long as the currently active generation isn't one of them. (don't delete the one you're standing on, babe π)
β Keep most-recent by count (number of generations)
$ nix-env --delete-generations +5
Say 30 is the current generation, and you've currently got generations numbered 20 through 32.
Then this command deletes generations 20 through 25 (<= 30 - 5), and keeps generations 26 through 31 (> 30 - 5). math ate, honestly π
β³ Keep most-recent by time (number of days)
$ nix-env --delete-generations 30d
This one deletes all generations older than 30 days β except for the generation that was active 30 days ago, if it still exists. sentimental exception β¨
π§Ή Delete all older
$ nix-env --profile other_profile --delete-generations old
and that's the whole page! π if you made it here you're literally a Nix scholar now, no cap.
okay so that was nix-env --delete-generations(1) β Nix 2.34.7, dated 2026-02-06 π slay, go delete some generations responsibly, bestie π
π¦
π¦ 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