✦ For everyone, free.

Practical knowledge for real and everyday life

Home

User-Scoped and Multi-User Nix

User-Scoped and Multi-User Nix enables isolated package management across users, offering flexibility and control in Linux system environments.

User-Scoped and Multi-User Nix refer to two primary modes of operating the Nix package manager, each designed to accommodate different system usage scenarios and security models. Nix is a purely functional package manager that builds and manages packages in isolated environments, allowing multiple versions of software to coexist without conflicts.


Definition and Overview

User-Scoped Nix is a mode where the Nix package manager is installed and operated entirely within a single user's environment. This installation does not require administrative privileges and confines package management and build processes to the user’s home directory. It is ideal for users who want to manage packages independently without affecting the global system or other users.

Multi-User Nix, on the other hand, is designed for system-wide installation and management of packages. It requires administrative privileges to install and configure but supports multiple users on the same system, allowing them to share the global Nix store, build results, and package caches. This mode enforces security boundaries between users and ensures system-wide consistency and efficiency.


User-Scoped Nix

Installation and Environment

User-scoped Nix can be installed without root privileges. It typically resides in the user’s home directory under paths such as ~/.nix-profile and ~/.nix-defexpr. The Nix store (where packages and build artifacts reside) is also user-specific, often located under ~/.nix-store or a similar directory.

This installation type uses environment variables such as PATH, NIX_PATH, and NIX_PROFILES configured in user shell profiles (e.g., .bashrc or .zshrc) to ensure the user’s shell environment loads the correct package versions and dependencies.

Advantages

  • No root or sudo access required.
  • Users can install and manage packages without affecting other users.
  • Ideal for development, experimentation, or isolated environments.
  • Simplifies sandboxing and avoids potential conflicts with system packages.

Limitations

  • Disk space usage can be inefficient since each user maintains a separate store.
  • Build caches and binaries are not shared, leading to redundant builds.
  • Less suitable for production environments or multi-user systems where consistent environments are required.

Usage and Commands

User-scoped Nix operations are the same as regular Nix commands, but all paths and settings are scoped within the user environment. For example:

nix-env -iA nixpkgs.hello

installs the hello package into the user profile, which only affects the current user.


Multi-User Nix

Installation and Architecture

Multi-user Nix requires root privileges for installation because it sets up a shared Nix store, typically at /nix/store. This global store contains all package builds and artifacts accessible to all users. The installation also sets up a daemon (nix-daemon) that manages build requests and enforces security policies.

The daemon runs with elevated privileges but isolates build processes in sandboxes, ensuring users cannot interfere with each other's builds or the system.

Security Model

Multi-user Nix employs a security model that prevents unprivileged users from modifying the global store directly. Instead, users submit build requests to the daemon, which verifies and executes builds under controlled conditions. This prevents malicious or accidental corruption of shared resources.

Access controls are implemented via Unix user permissions, group memberships (often a nix-users group), and the use of sandboxing techniques such as namespaces and seccomp filters.

Shared Resources and Efficiency

Because all users share the same store and build results, multi-user Nix maximizes disk space efficiency and build reuse. When one user builds a package, the resulting store path is available to all other users, eliminating redundant builds and downloads.

The global configuration enables caching of build results and binary substitutes, speeding up package deployment across multiple users.

Environment Setup

Multi-user Nix requires system-wide environment configuration to make installed packages available. This is typically done through profile scripts, systemd units, or login shell modifications that add /nix/var/nix/profiles/default/bin or user-specific profiles to the PATH.

Users manage their own profiles using commands like:

nix-env -iA nixpkgs.firefox

which installs Firefox into their personal profile but reuses the global store for binaries and dependencies.

Administration

System administrators manage the multi-user installation, including configuring the daemon, setting up trusted users, and maintaining cache servers or binary substitutes. This central control allows for consistent package versions and policy enforcement across the organization.


Comparison and Use Cases

AspectUser-Scoped NixMulti-User Nix
InstallationPer user, no root requiredSystem-wide, requires root
Store LocationUser’s home directory/nix/store global location
SecurityLimited sandboxing, user isolatedDaemon-enforced builds and sandboxing
Disk UsagePer user, redundant storageShared store, efficient usage
Build SharingNo sharing, each user builds separatelyBuild results shared among users
Suitable ForSingle-user machines, non-root usersMulti-user systems, servers, production
AdministrationUser-managedAdmin-managed with central control

Technical Details of Operation

Build Isolation

Both modes use Nix’s pure functional build model, but multi-user mode employs enhanced sandboxing via the daemon. Sandboxes use kernel features like namespaces and chroot to isolate builds and prevent side effects.

Profiles and Channels

Users in both modes manage their own profiles, which are collections of installed packages represented as symlinks to store paths. Channels define the set of available packages and their versions, which can be user-specific or system-wide.

Garbage Collection

Nix manages garbage collection of unused store paths. In user-scoped installations, garbage collection can be performed by the user without affecting others. In multi-user mode, coordinated garbage collection must consider all users’ profiles to avoid deleting shared dependencies in use.


Summary

User-Scoped Nix provides a lightweight, isolated approach to package management without system-wide impact, suitable for individual users without admin privileges. Multi-User Nix offers a robust, secure, and efficient environment for multiple users to share packages and build results on the same system, relying on a privileged daemon and global store. The choice between them depends on system administration policies, user requirements, and deployment scale.