Learn Nix

Nix is a general-purpose build tool, like a modern reinvention of Make that uses file hashes instead of timestamps. Haskell fans love it because all of the configuration is written in a lazy lambda calculus. This foundation gives Nix so much expressive power that it can build an entire Linux distribution (NixOS) with a single command.

No mutable state in the build process means no need for anything like “make clean,” and generally much less room to make mistakes. And provisioning a VM in the cloud with NixOS is just as easy as running NixOS on your laptop.

We use and promote the set of things that are joined together under the name Nix, for very similar reasons to the reasons we like Haskell.

This section of the site will be devoted to all things Nix, from the basics through practical and sometimes novel applications such as how we’ve used Nix in building LaTeX projects and this web site. (This site is mainly written in Haskell, but Nix plays an important role.)

What is Nix?

Nix is a language.

The Nix language is a lazy lambda calculus, a minimal programming language that was designed expressly for configuring Nix packages (see below). Since it is a lazy lambda calculus, it can’t really do side effects; for the most part, all it can do is evaluate expressions to a value. However, since it was designed for configuring packages, it has a few built-in features for the limited side effects required for that purpose. We list it first because Nix the language is pervasive throughout the other uses of the name Nix: it is the language the package configurations are written in; it is the language your NixOS configuration is written in and you may use it on the command line, especially with NixOS and NixOps, where commands may be Nix expressions. There is a REPL available for the Nix language.

Nix is a package manager.

The Nix package manager can be used on many operating systems. This package manager, unlike others such as apt, focuses on atomic, reproducible builds. Builds are reproducible because each package’s dependencies are explicitly declared and bundled so that everything the package needs is installed when you install the package. So, if you can build a Nix package on one machine, you can also build it on another machine. Builds are atomic in that installing or updating a package can’t break other packages because Nix does not overwrite the dependencies for any other package on the machine.

Nix is an operating system.

NixOS is, at its simplest, the package manager – but now it builds your Linux kernel, the whole operating system, and all its dependencies and packages. One of the things we love most about it, especially after being burned by some “security updates” on other operating systems that went badly wrong, is that you can always roll back to an earlier configuration of your NixOS machine because no build overwrites earlier builds. Another thing we love is how easy provisioning a new machine can be, because you can specify packages to install as it builds your OS right in your configuration file. This is especially awesome for servers, although we both use NixOS on our home machines as well.

Nix is also NixOps.

NixOps is a tool for deploying multiple NixOS machines ~in the cloud.~

Type Classes offers courses and projects to get you started and make you an expert in FP with Haskell. For $29/month, you get access to the complete archive and all the latest content.