User Profiles#

Each home directory has a so-called user profile, which allows to have separate packages and versions compared to the OS. User profiles are thus a powerful mechanism to tailor an application’s runtime environment to the exact needs of the deployment.

A user profile consists of a directory tree in ~/.nix-profile, consisting of the usual subdirectories like bin, include, lib, etc.

Using non-standard base OS packages#

Packages which are present in the standard nixpkgs distribution but not installed system-wide can be installed in the user profile with nix-env. See for a list of available packages.

Example: Installing libjpeg-turbo#

Consider an application needs to compile against libjpeg-turbo. Installing the package via nix-env -i makes shared libraries and include files available in ~/.nix-profile:

$ nix-env -i -A nixos.libjpeg
$ ls ~/.nix-profile/lib
$ ls ~/.nix-profile/include

You can only install versions provided via the base OS using this method. However, packages installed using this approach can pick up security updates quite easily with nix-env -u. See ChangeLog for information of security updates provided by the Flying Circus support team.

See nix-env(1) for further options.

Custom user environments#

If more control needs to be excercised on a user profile, we recommend building a custom environment with userEnv. This means that packages from arbitrary sources can be mixed and pinned to specific versions. In addition, own Nix expressions can be included.

Basic userEnv#

Create a file like userenv.nix which bundles required packages:

 2  # pinned import, see
 3  nixos_18_03 = fetchTarball;
 4  pkgs = import nixos_18_03 {};
 6pkgs.buildEnv {
 7  name = "myproject-env";
 8  paths = with pkgs; [
 9    ffmpeg
10    nodejs-8_x
11    electron
12  ];
13  extraOutputsToInstall = [ "out" "dev" "bin" "man" ];

The code shown above defines a userEnv with 3 packages installed from a specific build of NixOS 18.03.

Dry-run this expression with:

nix-build userenv.nix

A result symlink now points to the generated environment. It can be inspected and used manually, but is not yet an active part of the user profile.


nix-env -i -f userenv.nix

to install this userEnv in your profile. Now its binaries are available in PATH and libraries/include files should get found by the compiler.

XXX list env vars

To update a userEnv, simply update the source and install it again via nix-env.

Mixing packages from different sources#

Custom shell initializaton#

Fitting the RPATH of 3rd-party binary objects#