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 / -f path β€” Specifies the Nix expression (called below the active Nix expression) that --install, --upgrade, and --query --available use 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 / -p path β€” 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-generations and --rollback operations, this flag makes nix-env print 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-filter system β€” By default, operations like --query --available show derivations matching any platform. This option lets you use derivations for the specified platform system. 🌈

<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-format format β€” changes how the log output is formatted, 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.
  • 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 in prefix/nix/var/log/nix. πŸ“
  • --max-jobs / -j number β€” sets the max number of build jobs Nix will run in parallel to number. specify auto to use the number of CPUs in the system. the default comes from the max-jobs configuration setting, which itself defaults to 1. 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 the NIX_BUILD_CORES environment 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 attribute enableParallelBuilding is set to true, the builder passes the -jN flag to GNU Make. it defaults to the value of the cores configuration setting, if set, or 1 otherwise. the value 0 means 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 the max-silent-time configuration setting. 0 means no time-out.
  • --timeout β€” sets the max number of seconds that a builder can run. the default is specified by the timeout configuration setting. 0 means 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. 🚫
  • --arg name value β€” this option is accepted by nix-env, nix-instantiate, nix-shell and nix-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-file name path β€” passes the contents of file path as the argument name to Nix functions.
  • --arg-from-stdin name β€” passes the contents of stdin as the argument name to Nix functions.
  • --argstr name 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 / -A attrPath β€” selects an attribute from the top-level Nix expression being evaluated. (nix-env, nix-instantiate, nix-build and nix-shell only.) the attribute path attrPath is a sequence of attribute names separated by dots. for instance, given a top-level Nix expression e, the attribute path xorg.xorgserver would cause the expression e.xorg.xorgserver to be used. see nix-env --install for 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-store store-url β€” the URL to the Nix store to use for evaluation, i.e. where to store derivations (.drv files) 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-build and nix-shell only.)

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 / --include path β€” 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.
  • --option name value β€” sets the Nix configuration option name to value. this overrides settings in the Nix configuration file (see nix.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 under nix-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/default otherwise. 🫢

πŸ’– 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/store resolves to different locations) could totally yield different results. usually that's not a problem, except when builds get deployed to machines where /nix/store resolves differently. so if you're 100% sure you're not gonna do that, you can set NIX_IGNORE_SYMLINK_STORE to 1.

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 the libstore:store-dir build 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 the log-dir build 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, where localstatedir is 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 to daemon-socket/socket inside the state directory (that's NIX_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 to 1 and Nix prints some evaluation statistics, like how many values got allocated. numbers go brrr πŸ“Š
  • NIX_COUNT_CALLS β€” set it to 1 and 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 is 384 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:

  1. $NIX_CONFIG_HOME, if it is defined
  2. otherwise, the platform default (e.g. $XDG_CONFIG_HOME/nix on 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 by nix-shell. it can have the values pure or impure. 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 ~/.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 after XDG_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 a is an empty string and b is a number, a is considered less than b
  • 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