NIX-ENV-UPGRADE(1)
β¨ nix-env --upgrade(1) β¨
okay so bestie, welcome to the General Commands Manual π entry for nix-env --upgrade β the glow-up command π
πΈ NAME πΈ
nix-env --upgrade β upgrade packages in user environment π¦
β SYNOPSIS β
nix-env {--upgrade | -u} args [--lt | --leq | --eq | --always]
[{--prebuilt-only | -b}] [{--attr | -A}] [--from-expression] [-E]
[--from-profile path] [--preserve-installed | -P]
π DESCRIPTION π
So the upgrade operation is literally building you a whole new user environment β¨ β it takes the current generation of the active profile as its base, and then swaps out every single store path that has a newer version hanging out in the set of paths described by args. Iconic.
Paths that have no newer version? Left completely untouched, bestie. And that is not an error π
. Also not an error: if some element of args matches, like, zero installed derivations. No drama, no error, we move on. π«Ά
Now β how exactly does args get mapped onto a set of store paths? That's a whole thing, and it's described under --install. Go read that one, iykyk. π
One more thing: if args describes multiple store paths that all share the same symbolic name, only the one with the highest version gets installed. The rest are giving background character energy. π
π FLAGS π
--ltβ Only upgrade a derivation to newer versions. This is the default, so if you don't say anything, this is the vibe you're getting. β--leqβ Not just newer versions β this one also "upgrades" to derivations that have the same version π¦. Here's the tea: version is not a unique identifier of a derivation, so there can be, like, a ton of derivations all rocking the same version. This flag is lowkey useful when you wanna force some "synchronisation" between the installed derivations and the available ones. π«--eqβ Only "upgrade" to derivations that have the same version. Okay yes it sounds useless at first glance π but bestie it actually is useful β say there's a new release of Nixpkgs and you want to replace your installed applications with the same versions, but built against newer dependencies. That way you cut down the number of dependencies just floating around on your system. π--alwaysβ Beyond upgrading to newer versions, this one also "upgrades" to derivations with the same version or a lower one. Yeah. That means derivations can genuinely get downgraded, depending on whatever happens to be available in the active Nix expression. π--prebuilt-only/-bβ Only use derivations that have a substitute registered β aka there's a pre-built binary you can just download instead of building the derivation yourself. So no packages get built from source. Zero compiling, zero waiting, we love a shortcut. π--preserve-installed/-Pβ Do not remove derivations whose name matches one of the derivations being installed. Why does this matter? Because normally, trying to have two versions of the same package installed in the same generation of a profile will blow up with an error when building the generation β file name clashes between the two versions, ugh π. But β that's not true for all packages, so this flag exists. π«Ά
β¨ OPTIONS β¨
These next ones are allowed for all nix-env operations, but ngl they might not always actually do anything.</purl> (mood.)
--file/-fpath β Specifies the Nix expression (called below the active Nix expression) that--install,--upgrade, and--query --availableuse to obtain derivations. The default is~/.nix-defexpr. π
And here's the cute part: if the argument starts with http:// or https://, it gets interpreted as the URL of a tarball that'll 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. No default.nix, no deal. π
--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, and exactly one of them is the current generation. π--dry-runβ For the--install,--upgrade,--uninstall,--switch-generation,--delete-generationsand--rollbackoperations, this flag makesnix-envprint out what it would do if this flag hadn't been specified β without actually doing any of it. Preview mode. Main character behaviour. π¦
And --dry-run also prints out which paths will be substituted (aka downloaded) and which paths will be built from source (because no substitute is available). So you know exactly what you're getting into. π₯
--system-filtersystem β By default, operations like--query --availableshow derivations matching any platform. This option lets you use derivations for the specified platformsystem. π
<divider>---</divider>
π COMMON OPTIONS π
okay so bestie, these are the β¨universalβ¨ options β like, most Nix commands accept these, no matter which one you're calling. think of it as the shared group chat everyone's in π
--helpβ prints a lil summary of the command syntax and then peaces out. that's it, that's the whole vibe.--versionβ prints the Nix version number on standard output and bounces. β--verbose/-vβ cranks up the verbosity of diagnostic messages printed on standard error. and here's the tea: for each Nix operation, the info printed on standard output is well-defined β any diagnostic stuff goes to standard error, never to standard output. π
this option can be specified multiple times (stack it, queen). currently these verbosity levels exist:
0"Errors only" β only prints the messages explaining why your Nix invocation failed. that's the bare minimum, the "we need to talk" energy.1"Informational" β prints useful messages about what Nix is doing. this is the default. π«Ά2"Talkative" β more informational messages.3"Chatty" β even more informational messages.4"Debug" β prints debug information.5"Vomit" β prints VAST amounts of debug information. π truly unhinged, truly iconic.
--quietβ turns the verbosity of diagnostic messages printed on standard error down. it's the inverse option to-v/--verbose. this can also be specified repeatedly β go read the verbosity levels list above, it's the same one.--log-formatformat β changes how the log output is formatted, where 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.
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, 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. π--max-jobs/-jnumber β sets the max number of build jobs Nix will run in parallel to number. specifyautoto 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 β slay 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 max 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 the builder should use all available CPU cores in the system. π--max-silent-timeβ sets the max 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 max number of seconds that a builder can run. the default is specified by thetimeoutconfiguration setting.0means no timeout.--keep-going/-kβ keeps 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). πͺ--keep-failed/-Kβ says that in case of a build failure, the temporary directory (usually in/tmp) where the build takes place should not be deleted. the path of the build directory gets printed as an informational message. π--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 where this is useful is when we have registered substitutes in order to perform binary distribution from, like, 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. so basically: installation from binaries falls back on installation from source. this option is not the default, since it's generally not desirable for a transient failure in obtaining the substitutes to lead to a full build from source (with all the related resource consumption that comes with it). π
--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. π«--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.) π¦
--arg-from-filename path β passes the contents of 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 β 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. 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. π
--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 contains the built packages ready for use, give 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 -I take precedence over the nix-path configuration setting and the NIX_PATH environment variable. π
--impureβ allows access to mutable paths and repositories.--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β 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, most Nix commands lowkey read your mind through these env vars. Here's the whole roster π
πΈ Configuration environment variables πΈ
these ones change how Nix loads its config. full details live in the configuration file documentation, but here's the vibe:
NIX_CONF_DIRβ overrides the system configuration directory.NIX_USER_CONF_FILESβ overrides where the user configuration files live.NIX_CONFIGβ lets you shove configuration settings in inline. instant, no file needed β¨
π Store setting environment variables π
NIX_IGNORE_SYMLINK_STOREβ normally, the Nix store directory (typically/nix/store) is not allowed to contain any symlink components. why? to prevent "impure" builds, periodt. builders sometimes "canonicalise" paths by resolving all symlink components, so builds on different machines (where/nix/storeresolves to different locations) could totally yield different results. usually that's not a problem, except when builds get deployed to machines where/nix/storeresolves differently. so if you're 100% sure you're not gonna do that, you can setNIX_IGNORE_SYMLINK_STOREto1.
ngl though, if you're symlinking the Nix store so you can park it on a different file system than the root one, on Linux you're way better off using bind mount points, like:
$ mkdir /nix
$ mount -o bind /mnt/otherdisk/nix /nix
go read the mount 8 manual page for the deets π«Ά
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, figured out at runtime using the%PROGRAMDATA%Known Folder.
also see the Store Types chapter β every store has a store setting that links 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, again, no compile-time setting; the default is%PROGRAMDATA%\nix\log, determined at runtime via 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 the location of the Nix state directory. 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.
the Local Store, Local Daemon Store, and Experimental SSH Store with filesystem mounted have per-store settings that override this too.
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 (that'sNIX_STATE_DIR, see above).
check the Local Daemon Store documentation for how the socket path actually gets resolved π
TMPDIRβ use the directory you name here to store temporary files. this includes temporary build directories in particular, and those can eat substantial amounts of disk space, so choose wisely. default is/tmp.NIX_REMOTEβ overrides the store setting.
π§ Nix language evaluator settings π§
NIX_SHOW_STATSβ set it to1and Nix prints some evaluation statistics, like how many values got allocated. numbers go brrr πNIX_COUNT_CALLSβ set it to1and Nix tells you how often functions were called during Nix expression evaluation. perfect for profiling your Nix expressions fr fr.GC_INITIAL_HEAP_SIZEβ if Nix was configured to use the Boehm garbage collector, this sets the initial heap size in bytes. default is384 MiB. setting it low reduces memory consumption but makes runtime go up, because garbage collection overhead. it's giving tradeoff π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.
you can extend it with 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. not sometimes. always. π
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. these env vars override where those live:
- user configuration directory:
NIX_CONFIG_HOME(#user-conf-dir,#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 (experimental) use the proper directories by default, slay.
when use-xdg-base-directories is enabled, the configuration directory is resolved like this:
$NIX_CONFIG_HOME, if it is defined- otherwise, the platform default (e.g.
$XDG_CONFIG_HOME/nixon Unix)
same deal 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. vibe check incoming π
πΈ Appendix: OS-specific conventions πΈ
just so you know: none of this is Nix-specific, it's just stuff referenced above π«Ά
π§ Unix: XDG Base Directories
the XDG Base Directory Specification defines standard locations for user-specific configuration, state, and cache files on Unix systems.
these env vars are the ones in play:
XDG_CONFIG_HOME(#env-XDGCONFIGHOME) β default~/.configXDG_STATE_HOME(#env-XDGSTATEHOME) β default~/.local/stateXDG_CACHE_HOME(#env-XDGCACHEHOME) β default~/.cacheXDG_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 β¨
check it, upgrading one package by attr:
$ nix-env --upgrade --attr nixpkgs.gcc
upgrading `gcc-3.3.1' to `gcc-3.4'
when there are no updates available, nothing happens. literally nothing, the silence is deafening π
$ nix-env --upgrade --attr nixpkgs.pan
using -A is preferred when you can, because it's faster and unambiguous β but you can also upgrade to a specific version by matching the derivation name:
$ nix-env --upgrade gcc-3.3.2 --always
upgrading `gcc-3.4' to `gcc-3.3.2'
and if you want to try upgrading everything (matching packages based on the part of the derivation name without the version):
$ nix-env --upgrade
upgrading `hello-2.1.2' to `hello-2.1.3'
upgrading `mozilla-1.2' to `mozilla-1.4'
π Versions π
so how does the upgrade operation even decide if a derivation y is an upgrade of a derivation x? it looks at their respective name attributes, bestie. the names (like, say, gcc-3.3.1) get split into two parts: the package name (gcc) and the version (3.3.1). the version part starts after the first dash not followed by a letter. y counts as an upgrade of x if their package names match and the version of y is higher than that of x. no cap.
versions get compared by splitting them into contiguous components of numbers and letters. e.g., 3.3.1pre5 splits into [3, 3, 1, "pre", 5]. these lists are then compared lexicographically (left to right). corresponding components a and b are compared like this:
- if they're both numbers, integer comparison is used
- if
ais an empty string andbis a number,ais considered less thanb - the special string component
pre(for pre-release) is considered less than other components - string components are considered less than number components
- otherwise, they're compared lexicographically (case-sensitive string comparison, bestie)
this is illustrated by the following examples:
1.0 < 2.3
2.1 < 2.3
2.3 = 2.3
2.5 > 2.3
3.1 > 2.3
2.3.1 > 2.3
2.3.1 > 2.3a
2.3pre1 < 2.3
2.3pre3 < 2.3pre12
2.3a < 2.3c
2.3pre1 < 2.3c
2.3pre1 < 2.3q
and that's a wrap on nix-env --upgrade(1) π thanks for reading all the way to the bottom, you're genuinely the main character for that. drink some water, go upgrade something, and remember: -A is your 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