• How does Nix handle profiles?

  • Sources:

    Nix handles profiles through a unique system that involves creating and managing derivations, which are essentially build recipes for packages. When you install a package in Nix, it builds the package if it's not already available as a pre-built binary. The package, along with its dependencies, gets stored in the Nix Store and is identified through a unique hash and name.

    Nix then creates profiles, which are snapshots of installed packages or groups of packages. These profiles are essentially directories with symbolic links to relevant package files in the Nix store. When you install a package, Nix updates the profile to include all previously installed packages plus the new one, building an immutable sequence. Uninstalling a package involves creating a new profile version without that package. This design allows for efficient garbage collection and supports atomic upgrades by simply switching which profile’s symbolic links are active1 .

    Each user can have their profiles, and there's also a system profile for the OS. Nix handles garbage collection by determining which files in the Nix store aren’t referenced by any of the active profiles. Thus, individual user profiles ensure that user-specific packages aren’t mistakenly removed during garbage collection2 .

    This structure supports multi-user environments by appending paths from user profiles first, followed by system profiles, ensuring that user-specific binaries take precedence when executed2 .

    RELATED QUESTIONS