nix-env 1 Nix nix-env manipulate or query Nix user environments nix-env name value path path system operation options arguments Description The command nix-env is used to manipulate Nix user environments. User environments are sets of software packages available to a user at some point in time. In other words, they are a synthesised view of the programs available in the Nix store. There may be many user environments: different users can have different environments, and individual users can switch between different environments. nix-env takes exactly one operation flag which indicates the subcommand to be performed. These are documented below. Common options This section lists the options that are common to all operations. These options are allowed for every subcommand, though they may not always have an effect. See also . Specifies the Nix expression (designated below as the active Nix expression) used by the , , and operations to obtain derivations. The default is ~/.nix-defexpr. Specifies the profile to be used by those operations that operate on a profile (designated below as the active profile). A profile is sequence of user environments called generations, one of which is the current generation. The default profile is the target of the symbolic link ~/.nix-profile (see below). For the , , , and operations, this flag will cause nix-env to print what would be done if this flag had not been specified, without actually doing it. also prints out which paths will be substituted (i.e., downloaded) and which paths will be built from source (because no substitute is available). system By default, operations such as only include derivations matching the current platform. This option allows you to use derivations for the specified platform system. The special value * causes derivations for any platform to be included. Files ~/.nix-defexpr The default Nix expression used by the , , and operations to obtain derivations. The option may be used to override this default. ~/.nix-profile A symbolic link to the user's current profile. By default, this symlink points to prefix/var/nix/profiles/default. The PATH environment variable should include ~/.nix-profile/bin for the user environment to be visible to the user. Operation <option>--install</option> Synopsis nix-env args Description The install operation creates a new user environment, based on the current generation of the active profile, to which a set of store paths described by args is added. The arguments args map to store paths in a number of possible ways: By default, args is a set of derivation names denoting derivations in the active Nix expression. These are realised, and the resulting output paths are installed. Currently installed derivations with a name equal to the name of a derivation being added are removed unless the option is specified. If there are multiple derivations matching a name in args that have the same name (e.g., gcc-3.3.6 and gcc-4.1.1), then only the highest version will be installed. You can force the installation of multiple derivations with the same name by being specific about the versions. For instance, nix-env -i gcc-3.3.6 gcc-4.1.1 will install both version of GCC (and will probably cause a user environment conflict!). If () is specified, the arguments are attribute paths that select attributes from the top-level Nix expression. This is faster than using derivation names and unambiguous. To find out the attribute paths of available packages, use nix-env -qaA '*'. If path is given, args is a set of names denoting installed store paths in the profile path. This is an easy way to copy user environment elements from one profile to another. If is given, args are Nix functions that are called with the active Nix expression as their single argument. The derivations returned by those function calls are installed. This allows derivations to be specified in a unambiguous way, which is necessary if there are multiple derivations with the same name. If args are store derivations, then these are realised, and the resulting output paths are installed. If args are store paths that are not store derivations, then these are realised and installed. Flags Do not remove derivations with a name matching one of the derivations being installed. Usually, trying to have two versions of the same package installed in the same generation of a profile will lead to an error in building the generation, due to file name clashes between the two versions. However, this is not the case for all packages. Examples To install a specific version of gcc from the active Nix expression: $ nix-env --install gcc-3.3.2 installing `gcc-3.3.2' uninstalling `gcc-3.1' Note the the previously installed version is removed, since was not specified. To install an arbitrary version: $ nix-env --install gcc installing `gcc-3.3.2' To install using a specific attribute: $ nix-env -i -A gcc40mips $ nix-env -i -A xorg.xorgserver To install all derivations in the Nix expression foo.nix: $ nix-env -f ~/foo.nix -i '*' To copy the store path with symbolic name gcc from another profile: $ nix-env -i --from-profile /nix/var/nix/profiles/foo -i gcc To install a specific store derivation (typically created by nix-instantiate): $ nix-env -i /nix/store/fibjb1bfbpm5mrsxc4mh2d8n37sxh91i-gcc-3.4.3.drv To install a specific output path: $ nix-env -i /nix/store/y3cgx0xj1p4iv9x0pnnmdhr8iyg741vk-gcc-3.4.3 To install from a Nix expression specified on the command-line: $ nix-env -f ./foo.nix -i -E \ 'f: (f {system = "i686-linux";}).subversionWithJava' I.e., this evaluates to (f: (f {system = "i686-linux";}).subversionWithJava) (import ./foo.nix), thus selecting the subversionWithJava attribute from the attribute set returned by calling the function defined in ./foo.nix. A dry-run tells you which paths will be downloaded or built from source: $ nix-env -f pkgs/top-level/all-packages.nix -i f-spot --dry-run (dry run; not doing anything) installing `f-spot-0.0.10' the following derivations will be built: /nix/store/0g63jv9aagwbgci4nnzs2dkxqz84kdja-libgnomeprintui-2.12.1.tar.bz2.drv /nix/store/0gfarvxq6sannsdw8a1ir40j1ys2mqb4-ORBit2-2.14.2.tar.bz2.drv /nix/store/0i9gs5zc04668qiy60ga2rc16abkj7g8-sqlite-2.8.17.drv ... the following paths will be substituted: /nix/store/8zbipvm4gp9jfqh9nnk1n3bary1a37gs-perl-XML-Parser-2.34 /nix/store/b8a2bg7gnyvvvjjibp4axg9x1hzkw36c-mono-1.1.4 ... Operation <option>--upgrade</option> Synopsis nix-env args Description The upgrade operation creates a new user environment, based on the current generation of the active profile, in which all store paths are replaced for which there are newer versions in the set of paths described by args. Paths for which there are no newer versions are left untouched; this is not an error. It is also not an error if an element of args matches no installed derivations. For a description of how args is mapped to a set of store paths, see . If args describes multiple store paths with the same symbolic name, only the one with the highest version is installed. Flags Only upgrade a derivation to newer versions. This is the default. In addition to upgrading to newer versions, also “upgrade” to derivations that have the same version. Version are not a unique identification of a derivation, so there may be many derivations that have the same version. This flag may be useful to force “synchronisation” between the installed and available derivations. Only “upgrade” to derivations that have the same version. This may not seem very useful, but it actually is, e.g., when there is a new release of Nixpkgs and you want to replace installed applications with the same versions built against newer dependencies (to reduce the number of dependencies floating around on your system). In addition to upgrading to newer versions, also “upgrade” to derivations that have the same or a lower version. I.e., derivations may actually be downgraded depending on what is available in the active Nix expression. Examples $ nix-env --upgrade gcc upgrading `gcc-3.3.1' to `gcc-3.4' $ nix-env -u gcc-3.3.2 --always (switch to a specific version) upgrading `gcc-3.4' to `gcc-3.3.2' $ nix-env --upgrade pan (no upgrades available, so nothing happens) $ nix-env -u '*' (try to upgrade everything) upgrading `hello-2.1.2' to `hello-2.1.3' upgrading `mozilla-1.2' to `mozilla-1.4' Versions The upgrade operation determines whether a derivation y is an upgrade of a derivation x by looking at their respective name attributes. The names (e.g., gcc-3.3.1 are split into two parts: the package name (gcc), and the version (3.3.1). The version part starts after the first dash not following by a letter. x is considered an upgrade of y if their package names match, and the version of y is higher that that of x. The versions are compared by splitting them into contiguous components of numbers and letters. E.g., 3.3.1pre5 is split into [3, 3, 1, "pre", 5]. These lists are then compared lexicographically (from left to right). Corresponding components a and b are compared as follows. If they are 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 to be less than other components. String components are considered less than number components. Otherwise, they are compared lexicographically (i.e., using case-sensitive string comparison). 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 Operation <option>--uninstall</option> Synopsis nix-env drvnames Description The uninstall operation creates a new user environment, based on the current generation of the active profile, from which the store paths designated by the symbolic names names are removed. Examples $ nix-env --uninstall gcc $ nix-env -e '*' (remove everything) Operation <option>--query</option> Synopsis nix-env attribute-path names Description The query operation displays information about either the store paths that are installed in the current generation of the active profile (), or the derivations that are available for installation in the active Nix expression (). It only prints information about derivations whose symbolic name matches one of names. The wildcard * shows all derivations. The derivations are sorted by their name attributes. Source selection The following flags specify the set of things on which the query operates. The query operates on the store paths that are installed in the current generation of the active profile. This is the default. The query operates on the derivations that are available in the active Nix expression. Queries The following flags specify what information to display about the selected derivations. Multiple flags may be specified, in which case the information is shown in the order given here. Note that the name of the derivation is shown unless is specified. Print the result in an XML representation suitable for automatic processing by other tools. The root element is called items, which contains a item element for each available or installed derivation. The fields discussed below are all stored in attributes of the item elements. Print the status of the derivation. The status consists of three characters. The first is I or -, indicating whether the derivation is currently installed in the current generation of the active profile. This is by definition the case for , but not for . The second is P or -, indicating whether the derivation is present on the system. This indicates whether installation of an available derivation will require the derivation to be built. The third is S or -, indicating whether a substitute is available for the derivation. Print the attribute path of the derivation, which can be used to unambiguously select it using the option available in commands that install derivations like nix-env --install. Suppress printing of the name attribute of each derivation. / Compare installed versions to available versions, or vice versa (if is given). This is useful for quickly seeing whether upgrades for installed packages are available in a Nix expression. A column is added with the following meaning: < version A newer version of the package is available or installed. = version At most the same version of the package is available or installed. > version Only older versions of the package are available or installed. - ? No version of the package is available or installed. Print the system attribute of the derivation. Print the path of the store derivation. Print the output path of the derivation. Print a short (one-line) description of the derivation, if available. The description is taken from the meta.description attribute of the derivation. Examples $ nix-env -q '*' (show installed derivations) bison-1.875c docbook-xml-4.2 firefox-1.0.4 MPlayer-1.0pre7 ORBit2-2.8.3 ... $ nix-env -qa '*' (show available derivations) firefox-1.0.7 GConf-2.4.0.1 MPlayer-1.0pre7 ORBit2-2.8.3 ... $ nix-env -qas '*' (show status of available derivations) -P- firefox-1.0.7 (not installed but present) --S GConf-2.4.0.1 (not present, but there is a substitute for fast installation) --S MPlayer-1.0pre3 (i.e., this is not the installed MPlayer, even though the version is the same!) IP- ORBit2-2.8.3 (installed and by definition present) ... (show available derivations in the Nix expression foo.nix) $ nix-env -f ./foo.nix -qa '*' foo-1.2.3 $ nix-env -qc '*' (compare installed versions to what’s available) ... acrobat-reader-7.0 - ? (package is not available at all) autoconf-2.59 = 2.59 (same version) firefox-1.0.4 < 1.0.7 (a more recent version is available) ... (show info about a specific package, in XML) $ nix-env -qa --xml --description firefox ]]> Operation <option>--switch-profile</option> Synopsis nix-env path Description This operation makes path the current profile for the user. That is, the symlink ~/.nix-profile is made to point to path. Examples $ nix-env -S ~/my-profile Operation <option>--list-generations</option> Synopsis nix-env Description This operation print a list of all the currently existing generations for the active profile. These may be switched to using the operation. It also prints the creation date of the generation, and indicates the current generation. Examples $ nix-env --list-generations 95 2004-02-06 11:48:24 96 2004-02-06 11:49:01 97 2004-02-06 16:22:45 98 2004-02-06 16:24:33 (current) Operation <option>--delete-generations</option> Synopsis nix-env generations Description This operation deletes the specified generations of the current profile. The generations can be a list of generation numbers, or the special value old to delete all non-current generations. Periodically deleting old generations is important to make garbage collection effective. Examples $ nix-env --delete-generations 3 4 8 $ nix-env -p other_profile --delete-generations old Operation <option>--switch-generation</option> Synopsis nix-env generation Description This operation makes generation number generation the current generation of the active profile. That is, if the profile is the path to the active profile, then the symlink profile is made to point to profile-generation-link, which is in turn a symlink to the actual user environment in the Nix store. Switching will fail if the specified generation does not exist. Examples $ nix-env -G 42 switching from generation 50 to 42 Operation <option>--rollback</option> Synopsis nix-env Description This operation switches to the “previous” generation of the active profile, that is, the highest numbered generation lower than the current generation, if it exists. It is just a convenience wrapper around and . Examples $ nix-env --rollback switching from generation 92 to 91 $ nix-env --rolback error: no generation older than the current (91) exists