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 https://nixos.org/nixos/packages.html 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
jpeglib.h
[...]
$ ls ~/.nix-profile/include
libjpeg.la libjpeg.so.62 libjpeg.so libjpeg.so.62.2.0
[...]
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:
1let
2 # pinned import, see https://nixos.org/channels
3 nixos_18_03 = fetchTarball https://releases.nixos.org/nixos/18.03/nixos-18.03.132915.d6c6c7fcec6/nixexprs.tar.xz;
4 pkgs = import nixos_18_03 {};
5in
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" ];
14}
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.
Run
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
.