NIX-ENV-SET(1)

๐Ÿ’– nix-env --set(1) โ€” General Commands Manual ๐Ÿ’–

okay bestie, welcome to nix-env --set ๐Ÿ’… this is part of the nix-env manual, and this page is short but mighty, so let's get into it.


โœจ Name โœจ

nix-env --set โ€” set profile to contain a specified derivation

๐ŸŒธ Synopsis ๐ŸŒธ

nix-env --set drvname

๐Ÿฆ‹ Description ๐Ÿฆ‹

The --set operation modifies the current generation of a profile so that it contains exactly the specified derivation, and nothing else.

Like. exactly. Nothing else. It's giving "you are the entire vibe, there is no other vibe." ๐Ÿ‘‘


๐Ÿ’… Options ๐Ÿ’…

The following options are allowed for all nix-env operations, but may not always have an effect. (So they're always invited to the party, they just don't always dance. ๐Ÿ’ƒ)

  • --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.

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. ๐Ÿ“ฆโœจ

  • --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. ๐ŸŒฑ
  • --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. ๐Ÿ‘€ no cap, it just tells you.

--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). sneak peek energy ๐Ÿ”ฎ

  • --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. ๐Ÿ–ฅ๏ธ๐ŸŒˆ

more coming, bestie โ€” this page keeps going ๐Ÿ‘€

โœจ Common Options โœจ

okay so bestie, listen up ๐Ÿ‘‘ โ€” most Nix commands accept these command-line options. They're like the shared group chat of every Nix binary. Learn them once, use them everywhere. Periodt.


  • --help โ€” prints out a lil summary of the command syntax and then dips. That's it, that's the whole vibe.
  • --version โ€” prints the Nix version number on standard output and exits. Iconic, quick, done.
  • --verbose / -v โ€” turns the drama up on diagnostic messages printed to standard error. Here's the thing tho: for each Nix operation, what gets printed to standard output is well-defined; any diagnostic tea gets spilled to standard error, never to standard output. So stdout stays clean, stderr does the talking ๐Ÿ—ฃ๏ธ

This option can be specified repeatedly โ€” stack it, girl. Currently these are the verbosity levels that exist:

  • 0 โ€œErrors onlyโ€ โ€” only prints messages explaining why the Nix invocation flopped ๐Ÿ˜ญ
  • 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.
  • 4 โ€œDebugโ€ โ€” prints debug information.
  • 5 โ€œVomitโ€ โ€” prints vast amounts of debug information. Yes it's really called that ๐Ÿ’€
  • --quiet โ€” decreases the level of verbosity of diagnostic messages printed on standard error. It's the inverse option to -v / --verbose. Also stackable โ€” specify it repeatedly, babes. See the verbosity levels list above โ˜๏ธ
  • --log-format format โ€” changes the output of the log format, where format is one of these queens:
    • 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 hardcode your parsing and then act shocked, bestie ๐Ÿ™ˆ
  • bar โ€” only displays a progress bar during the builds. Minimalist slay.
  • bar-with-logs โ€” displays the raw logs, with the progress bar at the bottom. Best of both worlds fr fr.
  • --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. BUT โ€” and this is important โ€” the builder's standard output and error are always written to a log file in prefix/nix/var/log/nix. So nothing is lost, it's just not yelling at you anymore ๐Ÿซถ
  • --max-jobs / -j number โ€” sets the maximum number of build jobs that Nix will perform in parallel to the specified number. Specify 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. Get that parallelism, girl ๐Ÿ”ฅ

Setting it to 0 disallows building on the local machine โ€” which is useful when you want builds to happen only on remote builders. Bye local machine ๐Ÿ‘‹

  • --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 that the builder should use all available CPU cores in the system. All of them. Every last one ๐Ÿ’…
  • --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. So if your build is being silent, this is the vibe check it's failing ๐Ÿงš
  • --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. Live your truth, run forever, whatever.
  • --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). It's giving "we don't stop, we keep going" ๐Ÿ’ช
  • --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 need to go snooping through the wreckage ๐Ÿ”
  • --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). So like, it's the backup plan, not the plan ๐ŸŽ€

  • --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. Look but don't touch energy ๐Ÿšซ
  • --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.) Shell escaping is the enemy and it always has been ๐Ÿ˜ญ

  • --arg-from-file name path โ€” pass the contents of file path as the argument name to Nix functions. No quoting gymnastics required.
  • --arg-from-stdin name โ€” pass the contents of stdin as the argument name to Nix functions. Pipe it in and go ๐Ÿ“
  • --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. Way less screaming at your terminal.
  • --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, bestie, don't forget ๐Ÿง 

  • --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 contain the built packages ready for use, give your expression to the nix-shell --packages convenience flag instead. Different vibe, different flag ๐Ÿฆ‹

  • -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. Loud and clear, she goes first ๐Ÿ‘‘

  • --impure โ€” allow access to mutable paths and repositories. We're breaking the rules today I guess ๐Ÿ’…
  • --option name value โ€” set the Nix configuration option name to value. This overrides settings in the Nix configuration file (see nix.confโต). The โต means it's a manual page reference, iykyk.
  • --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. It's the deep-clean, not the tidy-up ๐Ÿงผ
๐Ÿ“ 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. That's where your profile actually lives, no cap ๐Ÿ 

โœจ Common Environment Variables โœจ

Okay so most Nix commands read these little guys, bestie โ€” here's the full lineup ๐Ÿ‘‡


๐Ÿ”ง Configuration environment variables

These ones decide how Nix loads its config. Full deets live in the configuration file documentation, but here's the vibe:

  • NIX_CONF_DIR โ€” overrides where the system configuration directory lives.
  • NIX_USER_CONF_FILES โ€” overrides the locations of the user configuration files.
  • NIX_CONFIG โ€” lets you feed configuration settings in inline, right there in the env. iconic.

๐Ÿฌ 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, and that's on purpose: it stops "impure" builds. Here's why, bestie: builders sometimes "canonicalise" paths by resolving all the symlink components. So if /nix/store resolves to different places on different machines, the same build could spit out different results. Usually that's fine, except when you deploy builds 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.

Heads up tho: if you're symlinking the Nix store just so you can park it on a different file system than root, on Linux you're way better off using bind mount points, like:

$ mkdir /nix
$ mount -o bind /mnt/otherdisk/nix /nix

Consult the mount 8 manual page for the details ๐Ÿ’…

  • NIX_STORE_DIR โ€” overrides where the Nix store is. On Unix, 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.

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 is. On Unix, default is /nix/var/log/nix, set at compile time by the log-dir build option. On Windows, no compile-time setting; 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 is. On Unix, default is ${localstatedir}/nix, where localstatedir is a compile-time build option defaulting to /nix/var. On Windows, no compile-time setting; 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 (peep NIX_STATE_DIR).

See the Local Daemon Store documentation for how the socket path actually gets resolved.

  • TMPDIR โ€” use this directory for temporary files. Specifically it includes temporary build directories, and those can eat up 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 prints how often functions got called during Nix expression evaluation. So useful for profiling your Nix expressions, fr.
  • GC_INITIAL_HEAP_SIZE โ€” if Nix was configured to use the Boehm garbage collector, this sets the initial heap size in bytes. Defaults to 384 MiB. Set it low and you use less memory, but runtime goes up because of garbage collection overhead. 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, and these environment variables override where they go:

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

When you don't set them, 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. slay.

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

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

Same energy 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.

๐Ÿ“Ž Appendix: OS-specific conventions

This info isn't Nix-specific at all, it's just referenced above. still valid tho ๐Ÿซถ

๐Ÿง Unix: XDG Base Directories

The XDG Base Directory Specification defines standard locations for user-specific configuration, state, and cache files on Unix systems.

These 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) โ€” a colon-separated list of additional configuration base directories, searched after XDG_CONFIG_HOME

๐ŸชŸ Windows: Known Folders

On Windows, Known Folders give you standard locations for application data on Windows.

The relevant folders:

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

๐ŸŒŸ Examples

The following updates a profile so that its current generation will contain just Firefox:

$ nix-env --profile /nix/var/nix/profiles/browser --set firefox

And that's a wrap on this whole page, bestie!! ๐ŸŽ‰ You officially survived every single environment variable Nix could possibly throw at you. This was pulled from the nix-env --set(1) page โ€” go be iconic with it ๐Ÿ‘‘๐Ÿ’–

๐Ÿ“ฆ where this page comes from