Skip to content

Understanding Nix

Nix is kind of a weird one. When I first found myself on its webpage, I'd arrived there having clicked something describing it as a functional language, but found myself facing this headline:

Declarative builds and deployments.

The website then went on to talk about Nix as tool, and one that solves package management and system configuration. At this point I've also noticed that I'm on nixos.org, which I've heard about but isn't the domain I expected to be on while digging into a functional language.

What exactly is Nix?

Nix is a tool to build... things. Those things can be software or configuration files, but we'll get to that later. There are lots of existing tools to do this; in fact, you're probably already familiar with Make. Let's start with that as a point of comparison.

Both Nix and Make:

  • are command line tools designed specifically for building software
  • use a specialized file format to describe the build process
  • have the concept of build inputs and outputs
  • eventually rely on scripts/shell commands to build the underlying software

How a build is defined is quite different between these tools, but for the sake of understanding what Nix is, I think Make is a reasonable comparison.

Of course, there's another catch: Nix isn't just a build tool; it's also a package manager that provides access to over 80,000 packages. So maybe Nix is actually more like apt/dpkg, Pacman, or Homebrew. 🤔

Ah, but wait, the file format Nix uses to describe the build process is actually a proper, purely-functional language, and that language is also called Nix. Despite the confusion, the decision to go with a functional language was actually really smart; Nix (the package manager) embraces Nix (the language)'s functional nature to elegantly dodge a bunch of typical package management problems.

Nix as a language

It's important to note that while Nix is a proper functional language, it's not a general purpose programming language. Its overall design, data types, and standard library cater specifically to building packages. There's still lots of flexibility when designing your own packages, just don't expect the kind of functionality or standard library of something like Elixir. 😅

Why should I care about Nix?

The language or package management benefits above might not sell you on Nix right away, and that's okay. The most important thing about any piece of tech is what you can actually do with it, and if you're not writing/maintaining software packages, or you haven't had to deal with the packaging problems Nix solves, you're unlikely to be swayed into using it.

For me, Nix alone wasn't all that appealing, but NixOS? That's another story.