User Package Management¶
NixOS allows users to manage packages independently from the base system. Service and normal users can install packages from nixpkgs or other sources in their user profile. This is a powerful mechanism to tailor an application's runtime environment to the exact needs of the deployment. You can also use this approach to install tools that you want to use interactively.
User packages are installed to ~/.nix-profile,
consisting of the usual subdirectories like bin, include, lib, etc
Installing packages that are already present in the system environment is safe. This doesn't use additional space if it's exactly the same package. Other versions, newer or older than system packages, can be installed without conflicts.
Custom User Environments¶
The user profile can be customized by building an environment with buildEnv
and installing it. Packages from arbitrary sources can be mixed and pinned
to specific versions.
{highlight} default
:linenothreshold: 3
let
# Imports. Which package sources should be used?
# Use a pinned platform version
# pkgs = import (fetchTarball "https://hydra.flyingcircus.io/build/457353/download/1/nixexprs.tar.xz") {};
# ...or just use the current version of the platform
pkgs = import <nixpkgs> {};
in
pkgs.buildEnv {
name = "myproject-env";
paths = with pkgs; [
libjpeg
zlib
ffmpeg
nodejs_18
electron
];
extraOutputsToInstall = [ "dev" ];
}
The code shown above defines an environment with 5 packages installed from a
specific build of our NixOS 24.05 platform.
The pinned version can be newer or older than the installed system version.
Pinning the version of the import prevents unwanted changes in your
application's dependencies but you are responsible for updating
the imports to get security fixes.
We recommend to keep the pinned version close to the system version to get the
latest security fixes. NixOS re-uses packages if the wanted version is already
in the Nix store, saving disk space and reducing installation time.
The URL for the current release can be found in the [changelog](../../changes/index.md)
for the 25.05 platform.
If you want to try NixOS unstable with the newest packages, get the URL from the channel:
Note that the unstable channel may be broken and that upstream NixOS channels
don't have some additional packages we provide on our platform.
Older NixOS versions than 25.05 usually don't get security updates anymore.
See <https://nixos.org/nixos/packages.html> for a list of packages.
Use the *attribute name* from the list and include it in `paths`.
The *attribute name* can differ from the *package name*.
For some packages, multiple versions are available.
Dry-run this expression with:
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
to install the env in your profile. Now its binaries are available in PATH
and libraries/include files should get found by the compiler.
To update, install the environment again with the same command.
This picks up changes in `myproject_env.nix` and package updates
(if the imports are not pinned to a specific version).
### Collisions With Existing Packages
Packages included in an environment can collide with packages from other environments
or with separately installed packages (we recommend not to do this).
You may encounter an error like this:
### Multiple Package Outputs
Packages can have multiple "outputs" which means that not all files are
installed by default. If you want to install libraries to build against,
including `dev` in `extraOutputsToInstall` should be sufficient.
You can check which outputs are available with the following command:
This installs the zlib from the platform NixOS version but libjpeg from NixOS unstable (here 25.05pre).