Nix

Nix is a cult providing an Operating System, package manager and a functional language.

How it works

At its core, everything in Nix is declared in code written in the Nix language. From this code, you can build artifacts that end up in the Nix store.

Most often, these artifacts are packages (derivations), but the system goes much further: you can compose entire environments, services, and even whole operating systems.

By rebuilding everything through Nix, you get a reproducible world of software where every build is fully pinned to an exact path in the Nix store, complete with all of its dependencies.

The Nix store then becomes a kind of universe: a place containing every version of every piece of software you’ve ever built (or could build), ready to be referenced, reused, and combined.

Outputs

Think of Nix as a declerative solution space for building anything. There are various things you can build with Nix:

  • Packages: a standard derivation is already a basic package, which can produce any set of files:
    • Binaries: prebuilt binaries for runtime
    • Libraries: shared libraries or codegen
    • Documentation: rendered documentation or man pages
    • Configuration: evaluated configuration files (eg. ini, json, systemd unit files)
    • Data: arbitary runtime data (eg. seclists, certificates)
    • Containers: via stdenv build container functions (.tar.gz OCI images)
  • Home Directories: via home-manager
  • Systems: NixOS system produces an entire operating system
  • Kubernetes Manifests: via kubenix
  • Terraform: via terranix
  • Websites: via styx

Keep in mind that these are mostly pluggable, it’s all data in the end, so you can compose these how you want and build even more complex or simple abstractions.

Concepts

  • Nix Language - The functional programming language powering everything
  • Nix Store - The Nix Store, a content and hash addressed path store for files
  • Derivation - A unit of computation, a directory stored in the nix store, commonly called a package
  • Nix Module - NixOS module system for composing configuration
  • Flakes - Repository level subpackaging for nix code
  • NixOS - Linux OS built around Nix

Modules

Tools