NIX-ENV-ROLLBACK(1)

πŸ’– nix-env --rollback πŸ’–

part of the nix-env(1) manual β€” like, the whole nix-env bestie-verse, but today we're hyperfixating on the rollback arc ✨


πŸŽ€ NAME πŸŽ€

nix-env --rollback β€” set user environment to previous generation

okay so literally what it says on the tin, bestie. you messed around, you found out, and now you wanna go back. iconic behaviour, honestly.


🌸 SYNOPSIS 🌸

nix-env --rollback

that's it. that's the whole vibe. one flag, no arguments, no drama πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

This operation switches to the "previous" generation of the active profile β€” meaning, the highest numbered generation lower than the current generation, if it even exists πŸ‘€

And like… that's a very specific way of saying "the one right before this one," which is exactly why it's phrased like that. It's not "the one you were on before," it's "the numerically highest one that's still less than where you are right now." Not the same thing!! if you've been hopping around, bestie, those two can absolutely be different generations 😭

It is just a convenience wrapper around --list-generations and --switch-generation. fr fr. it's giving "I could do this manually but I would rather not" energy, and honestly? valid.

lowkey the takeaway is: this is a shortcut, not a separate mechanism. if you know what --switch-generation does, you already know what this does 🫢

✨ OPTIONS ✨

The following options are allowed for all nix-env operations, but may not always have an effect. (Read that again, bestie β€” allowed everywhere, does something maybe. vibe check your expectations accordingly πŸ’€)

  • --file, -f path β€” Specifies the Nix expression (designated below as the active Nix expression) used by the --install, --upgrade, and --query --available operations to obtain derivations. The default is ~/.nix-defexpr.

And 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 🧚 The tarball must include a single top-level directory containing at least a file named default.nix. Single. Top-level. Directory. Not two, not zero. we do not negotiate with tarball layouts 😀

  • --profile, -p path β€” 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.

yep, that's the thing --rollback is about to mess with. profiles are basically a glow-up timeline and each generation is a save point ✨

  • --dry-run β€” For the --install, --upgrade, --uninstall, --switch-generation, --delete-generations and --rollback operations, this flag will cause nix-env to print what would be done if this flag had not been specified, without actually doing it.

πŸ›‘ NOT ME ROLLING BACK WITHOUT CHECKING FIRST πŸ›‘

--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 receipts before the thing happens. chef's kiss, no notes πŸŽ€

  • --system-filter system β€” By default, operations such as --query --available show derivations matching any platform. This option allows you to use derivations for the specified platform system.

so if you wanna be like "no babes, only this system," this is the flag that makes the query stop being a people-pleaser πŸ‘‘


ok so that's the top half of the page β€” generations, profiles, dry runs, the whole starter pack. there is more coming, don't you dare leave, we're only getting started πŸ’œ

✨ Common Options ✨

okay so, the vibe here is that most Nix commands accept the following command-line options. Not just some. Most. It's giving universal. πŸ’…

  • --help β€” prints out a summary of the command syntax and immediately exits. That's the whole job. No notes. 🫢
  • --version β€” prints out the Nix version number on standard output and exits. So you know exactly which era of Nix you're living in. ⭐
  • --verbose / -v β€” cranks up the level of verbosity of diagnostic messages printed on standard error. Important detail bestie: for each Nix operation, the stuff printed on standard output is well-defined, and any diagnostic info goes to standard error, never to standard output. Respect the separation. πŸ™Œ

You can pass this option over and over again to keep levelling up. Currently these verbosity levels exist:

  • 0 "Errors only" β€” only prints messages explaining why the Nix invocation failed. That's the tea and nothing else. 😭
  • 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 will not stop talking.
  • 4 "Debug" β€” prints debug information. πŸ”
  • 5 "Vomit" β€” prints vast amounts of debug information. Yes that's the actual name. It's iconic honestly.
  • --quiet β€” decreases the level of verbosity of diagnostic messages printed on standard error. It's literally the inverse option to -v / --verbose. 😌

You can also specify this repeatedly, and it walks back down the same verbosity levels list from above.

  • --log-format format β€” changes the output of the log format. format is one of:
    • raw β€” 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 don't get too comfy parsing it, bestie. πŸ™ˆ
  • bar β€” only displays a progress bar during the builds. Very demure, very minimal. 🌸
  • bar-with-logs β€” displays the raw logs, with the progress bar chillin' at the bottom.
  • --no-build-output / -Q β€” by default, output written by builders to standard output and standard error gets echoed to the Nix command's standard error. This option suppresses that behaviour. But heads up: 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 maximum number of build jobs that Nix will perform in parallel to number. Say auto to use the number of CPUs in the system. The default is specified by 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, which is useful when you want builds to happen only on remote builders. iykyk.

  • --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 maximum 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. Go off, queen. πŸ‘‘
  • --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 the max-silent-time configuration setting. 0 means no time-out. 🀐
  • --timeout β€” sets the maximum number of seconds that a builder can run. The default is specified by the timeout configuration setting. 0 means no timeout.
  • --keep-going / -k β€” keep going in case of failed builds, to the greatest extent possible. So like, 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). The drama. πŸ’€
  • --keep-failed / -K β€” says 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. Forensic girlies, this one's for you. πŸ”
  • --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, 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. So 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). Lore dropped. πŸ“š

  • --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. Not a hack, just a boundary. βœ‹
  • --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 β€” pass the contents of file path as the argument name to Nix functions.
  • --arg-from-stdin name β€” pass the contents of stdin as the argument name to Nix functions. Pipe it in, bestie. 🚰
  • --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. Shell peace preserved. πŸ•ŠοΈ
  • --attr / -A attrPath β€” select 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. Zero-indexed girlies rise. ✨

  • --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. Choose wisely. πŸŽ€

  • -I / --include path β€” 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. Priority queen. πŸ‘‘

  • --impure β€” allow access to mutable paths and repositories. Live a little. 😈
  • --option name value β€” set the Nix configuration option name to value. This overrides settings in the Nix configuration file (see nix.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 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, so most Nix commands read the following environment variables. Yes, most. They're just vibing in your shell, waiting to be noticed. πŸ’…

πŸŽ€ Configuration environment variables

These lil cuties decide how Nix loads its configuration. Full deets live in the configuration file documentation, but here's the tea:

  • NIX_CONF_DIR β€” overrides the system configuration directory. Yeah, the whole thing. πŸ‘‘
  • NIX_USER_CONF_FILES β€” overrides where the user configuration files live.
  • NIX_CONFIG β€” lets you just... provide configuration settings inline. Iconic, honestly.

πŸ“ Store setting environment variables

  • NIX_IGNORE_SYMLINK_STORE β€” so normally the Nix store directory (typically /nix/store) is not allowed to contain any symlink components. Why? To prevent "impure" builds, bestie. Builders sometimes "canonicalise" paths by resolving all symlink components. So builds on different machines β€” where /nix/store resolves to different locations β€” could yield different results. Wild, right? This is generally not a problem, EXCEPT when builds get deployed to machines where /nix/store resolves differently. If you're sure you're not gonna do that, you can set NIX_IGNORE_SYMLINK_STORE to 1. πŸ™ˆ

Also, quick PSA: if you're symlinking the Nix store so you can put it on another 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

Consult the mount 8 manual page for details. iykyk.

  • 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; 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 the log-dir build option. On Windows, 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, where localstatedir is 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.

Same trio applies here β€” 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 to daemon-socket/socket within the state directory (see NIX_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. Short and powerful, we love her. πŸ‘‘

🧚 Nix language evaluator settings

  • NIX_SHOW_STATS β€” if set to 1, Nix will print some evaluation statistics, such as the number of values allocated. Numbers go brrr. πŸ“Š
  • NIX_COUNT_CALLS β€” if set to 1, Nix will print how often functions were called during Nix expression evaluation. Super useful for profiling your Nix expressions, no cap.
  • 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. Tradeoffs, bestie, tradeoffs. 😭
  • 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:

  • user configuration directory: NIX_CONFIG_HOME
  • user state directory: NIX_STATE_HOME
  • user cache directory: NIX_CACHE_HOME

When these are not 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. ✨

When use-xdg-base-directories is enabled, the configuration directory is resolved as:

  1. $NIX_CONFIG_HOME, if it is defined
  2. Otherwise, the platform default (e.g. $XDG_CONFIG_HOME/nix on Unix)

Likewise for the state and cache directories. Same energy, different directories. πŸ’…

⭐ Miscellaneous environment variables

  • IN_NIX_SHELL β€” an indicator that tells if the current environment was set up by nix-shell. It can have the values pure or impure. That's it, that's the whole vibe check.

🌸 Appendix: OS-specific conventions 🌸

This info isn't Nix-specific, but it's referenced above, so here we are. πŸ’–

🐚 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 (default ~/.config)
  • XDG_STATE_HOME (default ~/.local/state)
  • XDG_CACHE_HOME (default ~/.cache)
  • XDG_CONFIG_DIRS (default /etc/xdg) β€” colon-separated list of additional configuration base directories, searched after XDG_CONFIG_HOME

πŸͺŸ Windows: Known Folders

On Windows, Known Folders provide standard locations for application data on Windows. (Yes, that's really what they're called, we don't make the rules. πŸŽ€)

The relevant folders are:

  • %APPDATA% β€” per-user roaming application data
  • %LOCALAPPDATA% β€” per-user local application data
  • %PROGRAMDATA% β€” system-wide application data

πŸ’« Examples πŸ’«

Rolling back like a boss:

$ nix-env --rollback
switching from generation 92 to 91

And the moment you hit the floor of your generation history, bestie:

$ nix-env --rollback
error: no generation older than the current (91) exists

😭 tragic. There's simply nothing older to go back to. Periodt.


And that's a wrap on nix-env --rollback(1), from the nix-env source, dated 2025 β€” same energy as ever, just cuter. Now go roll back something responsibly, bestie. πŸ‘‘πŸ’–βœ¨

πŸ“¦ where this page comes from