nix-env-install - Man Page

add packages to user environment

Synopsis

nix-env {--install | -i} args… [{--prebuilt-only | -b}] [{--attr | -A}] [--from-expression] [-E] [--from-profile path] [--preserve-installed | -P] [--remove-all | -r] [--priority priority]

Description

The --install operation creates a new user environment. It is 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:

nix-env --query --available --attr-path
# example.nix
let
pkgs = import <nixpkgs> {};
command = ''
  ${pkgs.coreutils}/bin/mkdir -p $foo $bar
  echo foo > $foo/foo-file
  echo bar > $bar/bar-file
​'';
in
derivation {
name = "example";
builder = "${pkgs.bash}/bin/bash";
args = [ "-c" command ];
outputs = [ "foo" "bar" ];
system = builtins.currentSystem;
}

Installing from this Nix expression will make files from both outputs appear in the current profile.

$ nix-env --install --file example.nix
installing 'example'
$ ls ~/.nix-profile
foo-file
bar-file
manifest.nix

Adding meta.outputsToInstall to that derivation will make nix-env only install files from the specified outputs.

# example-outputs.nix
import ./example.nix // { meta.outputsToInstall = [ "bar" ]; }
$ nix-env --install --file example-outputs.nix
installing 'example'
$ ls ~/.nix-profile
bar-file
manifest.nix

Options

Options

The following options are allowed for all nix-env operations, but may not always have an effect.

Common Options

Most Nix commands accept the following command-line options:

{ # 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.)

Environment variables

Common Environment Variables

Most Nix commands interpret the following environment variables.

Configuration environment variables

The following environment variables affect how Nix loads its configuration. See the configuration file documentation for full details.

  • NIX_CONF_DIR

    Overrides the system configuration directory.

  • NIX_USER_CONF_FILES

    Overrides the user configuration file locations.

  • NIX_CONFIG

    Provides configuration settings inline.

Store setting environment variables

  • NIX_IGNORE_SYMLINK_STORE

    Normally, the Nix store directory (typically /nix/store) is not allowed to contain any symlink components. This is to prevent “impure” builds. Builders sometimes “canonicalise” paths by resolving all symlink components. Thus, builds on different machines (with /nix/store resolving to different locations) could yield different results. This is generally not a problem, except when builds are deployed to machines where /nix/store resolves differently. If you are sure that you’re not going to do that, you can set NIX_IGNORE_SYMLINK_STORE to 1.

    Note that if you’re symlinking the Nix store so that you can put it on another file system than the root file system, on Linux you’re better off using bind mount points, e.g.,

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

Consult the mount 8 manual page for details.

  • 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 is 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, there is 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, there is 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.

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

Nix language evaluator settings

  • NIX_SHOW_STATS

    If set to 1, Nix will print some evaluation statistics, such as the number of values allocated.

  • NIX_COUNT_CALLS

    If set to 1, Nix will print how often functions were called during Nix expression evaluation. This is useful for profiling your Nix expressions.

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

  • 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]{#user-conf-dir}: [NIX_CONFIG_HOME]{#env-NIXCONFIGHOME}
  • user state directory: [NIX_STATE_HOME]{#env-NIXSTATEHOME}
  • user cache directory: [NIX_CACHE_HOME]{#env-NIXCACHEHOME}

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.

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.

Miscellaneous environment variables

  • IN_NIX_SHELL

    Indicator that tells if the current environment was set up by nix-shell. It can have the values pure or impure.

Appendix: OS-specific conventions

This information is not Nix-specific, but is 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.

The following environment variables are used:

  • [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) — 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.

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

To install a package using a specific attribute path from the active Nix expression:

$ nix-env --install --attr gcc40mips
installing `gcc-4.0.2'
$ nix-env --install --attr xorg.xorgserver
installing `xorg-server-1.2.0'

To install a specific version of gcc using the derivation name:

$ nix-env --install gcc-3.3.2
installing `gcc-3.3.2'
uninstalling `gcc-3.1'

Using attribute path for selecting a package is preferred, as it is much faster and there will not be multiple matches.

Note the previously installed version is removed, since --preserve-installed was not specified.

To install an arbitrary version:

$ nix-env --install gcc
installing `gcc-3.3.2'

To install all derivations in the Nix expression foo.nix:

$ nix-env --file ~/foo.nix --install '.*'

To copy the store path with symbolic name gcc from another profile:

$ nix-env --install --from-profile /nix/var/nix/profiles/foo gcc

To install a specific store derivation:

$ nix-env --install /nix/store/8la6y31fmm6i4wfmby6avly1wf718xnj-gcc-3.4.3.drv

To install a specific output path:

$ nix-env --install /nix/store/y3cgx0xj1p4iv9x0pnnmdhr8iyg741vk-gcc-3.4.3

To install from a Nix expression specified on the command-line:

$ nix-env --file ./foo.nix --install --expr \
    '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 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 --file '<nixpkgs>' --install --attr hello --dry-run
(dry run; not doing anything)
installing ‘hello-2.10’
this path will be fetched (0.04 MiB download, 0.19 MiB unpacked):
  /nix/store/ikwkxz4wwlp2g1428n7dy729cg1d9hin-hello-2.10
  ...

To install Firefox from the latest revision in the Nixpkgs/NixOS 14.12 channel:

$ nix-env --file https://github.com/NixOS/nixpkgs/archive/nixos-14.12.tar.gz --install --attr firefox