what-nix-is.md

What Nix is

Before this, you'll want

  1. Welcome to the course
The Nix language4 min

Every other lesson in this course asks you to do something. This one doesn’t. It simply lists the words you will meet the most and stops to explain what they actually mean.

If you came here, you have likely heard some of them before, so use this page to refresh your memory.

Four things are called Nix

One short name, four different meanings.

Type
Nixthe language. The only part of any of this that is code you writea language
nixthe command that reads it, works out what to build, and builds ita package manager
NixOSa Linux distribution assembled entirely by nixan operating system
nixpkgsa large collection of Nix code, packages and system optionsa repository

Notice how the language is capital-N Nix while the command you type is lowercase nix. NixOS is spelled like that by convention and reads “nix oh-ess”, not “niksos”.

Also note that NixOS is just one single way to use the package manager, definitely not the only one. nix runs on any Linux and on macOS, so a good half of this course is worth reading whether or not you will ever decide to install the operating system.

Declarative

On an ordinary system you install a program by running a command. So the machine you end up with is the sum of every command anybody has ever run on it, and that list doesn’t exist anywhere.

A declarative system asks a different question. Not what to run, but what should be true:

NixOS moduleA NixOS module, checked against real NixOS options and evaluated by the NixOS module system.
{
  programs.firefox.enable = true;
  networking.hostName = "workstation";
}

Nothing in there is an instruction. It is a description, and it reads exactly the same on a machine installed this morning and one installed three years ago.

Which is also why you can understand somebody’s machine by reading it, instead of by running it and finding out.

Reproducible

Reproducible is the word the whole ecosystem is built around, and it promises something much narrower than people assume. It does not mean the software has fewer bugs. It’s just the opposite of “works on my machine”, and nothing more than that.

Same inputs = same output

Evaluation, then building

The last one, and it sits behind half the error messages you are going to meet. Nix works in two separate steps, always in this order.

Evaluation is Nix reading your code and working out exactly what should be built. It usually happens in a matter of seconds.

Building on the other hand is the process of using the evaluated Nix code to construct packages from it. Almost everything in Nix is a package, but we will get to that later.

Most of this course lives in that first step. Compiling packages in your browser is an undertaking I decided to skip.

What to keep

  • Nix is a language and a package manager. NixOS is a Linux distribution built out of both. nixpkgs is where the packages live.
  • Declarative means describing the result rather than the commands that reach it.
  • Reproducible means the same inputs give the same result on another machine.
  • Nix evaluates everything before it builds anything.

Derivation, flake, module and overlay are the other words you’ll run into early. Each one gets a lesson of its own further down, and you don’t need any of them to follow the next one.

Useful links

NORMALCOURSE IN BETA