Published 2024-10-11 by Daniel Bark
Understanding Nix, Nixpkgs, and NixOS
Since you are here, you’ve probably come across the terms Nix, Nixpkgs, or NixOS. Although they are closely related, they serve different purposes. Let me walk you through how they relate to each other.
What is Nix?
Nix is a functional package manager. Unlike most package managers (like apt or yum), Nix takes a purely functional approach to package management.
This means that the installation, configuration, and management of software is done in a deterministic way, where the outcome of any action is fully defined by its inputs.
Some key features of Nix
- Atomic upgrades and rollbacks: Since Nix installs packages in isolated environments, it’s easy to roll back to a previous configuration.
- Isolated environments: Different versions of the same package can coexist without conflict, which is extremely useful for managing dependencies.
- Reproducibility: Because packages are built from immutable derivations (think recipe, order is important), you can reproduce the exact same environment.
What is Nixpkgs?
Nixpkgs is the repository of packages that Nix can use. It’s essentially a massive collection of package definitions and the build instructions required to install and manage software via Nix.
How Nixpkgs fits into the ecosystem:
-
Package Definitions: Nixpkgs contains thousands of packages, which Nix uses to fetch, build, and install software.
-
Nix expressions: The packages in Nixpkgs are written in the Nix expression language. These expressions define not just how to install a package, but also how to handle dependencies, build options, and more.
-
Community-driven: Nixpkgs is open source and updates are constantly flowing in to support new software versions or additional platforms.
What is NixOS?
NixOS is a Linux distribution built around the Nix package manager. It leverages the power of Nix for system configuration, package management, and even deployment. In NixOS, the entire operating system—kernel, system services, user packages, and configuration—is defined declaratively in the Nix language.
Key aspects of NixOS include:
-
Declarative Configuration: Instead of manually configuring your system through a combination of shell scripts and configuration files, you write a single configuration file in Nix. This file describes everything about the system—installed packages, services, hardware configuration, and more.
-
Reproducible Systems: Because everything in NixOS is declared in a configuration file, you can reproduce the exact same system. This makes it extremely appealing for both servers and development environments.
-
Transactional Upgrades: Just like with Nix’s package management, system upgrades in NixOS are atomic and can be rolled back if needed. This ensures that if something goes wrong after an update, you can always return to the last known good state.
How Nix, Nixpkgs, and NixOS relate to each other
-
Nix is the tool—the package manager—that installs and manages software in a functional way.
-
Nixpkgs is the collection of packages and build instructions that Nix uses to fetch, build, and install software.
-
NixOS is the complete operating system that leverages Nix for not only package management but also system configuration and deployment.
You can use Nix without using NixOS. For example, you can install Nix on other Linux distributions, macOS, or even Windows (through the Linux subsystem).
You’ll still be able to take advantage of the functional package management system that Nix provides, and use packages from Nixpkgs.
However, if you want the full, declarative operating system experience, then NixOS is where Nix really shines.
Summary
-
Nix is the functional package manager.
-
Nixpkgs is the collection of packages that Nix manages.
-
NixOS is the full Linux distribution that applies the principles of Nix to the entire operating system.
BEWARE
Nix can be extremely frustrating because of its steep learning curve and can feel very complex and unintuitive.
Cudos to all the nix users out there!
That is all! Have a great day!
Written by Daniel Bark
← Back to blog