NixOS 101 (UPDATED 2022-03-14)

Starting with NixOS - Intro

I’m writing this series of posts to:

  • a) Share my journey and problems I stumble(d) upon so that you can learn from my mistakes
  • b) Have a place to store my findings so I won’t have to remember all the solutions!

I’m a simple man so expect simple, easy to follow posts - nothing groundbreaking, but hopefully, still helpful.

The first steps

So, you want to try out NixOS but don’t know where to start? NixOS webpage and Nix Pills are an excellent source of knowledge, but the manuals can be a little bit overwhelming and off-putting when you’re just beginning your journey.

Image

I remember having a hard time when starting with NixOS. I’d open and study the manuals, but all I really wanted, was an installer, to get me through the boring and tedious hardware part so I could start exploring right away and dig in deeper into NixOS itself. But there is none, and there’s probably a good reason why, but more on that in next post.

TL;DR

  • Everything is managed declaratively through /etc/nixos/configuration.nix
  • Upgrades/installs are non-destructive (safe) and won’t break your system
  • System snapshots, called generations, do not contain user data

What NixOS is and what it is not.

NixOS is:

  • Purely functional. NixOS has got a fresh approach to some very old problems such as dependency hell or system breaking during upgrades. Dependency hell doesn’t exist, and the system is literally unbreakable™*.
  • Declarative. It’s built on top of Nix package manager and uses Nix Expression Language. This combination allows us to declaratively define the system configuration files, kernel, applications and services. No more “I don’t remember which configuration files I’ve modified” or “I’m not really sure how to enable insert_service_here”. All configuration is managed from one place - /etc/nixos/configuration.nix
  • Reliable. NixOS has got atomic, non-destructive upgrades, so if anything goes wrong during an upgrade or install - it fails, or you interrupt it, the system will stay in a consistent (previous) state. If you don’t like your new system, do a rollback!
  • Reproducible. Since it’s pure, you can be pretty sure you will always get the same output from the same input. There’s a nice website tracking the current progress.
  • Great for developers. With its nix-shell and other goodies for setting up environments easily and reliably, NOT breaking your workstation in the process.
  • Open Source. WYSIWYG - it’s built right from GitHub repo! It’s easy to contribute, and the community is very open-minded and super helpful.

* almost: Terms and Conditions apply (don’t screw up the bootloader)

NixOS is NOT:

  • New. Nix/OS itself is not particularly new as it started as a research project by Eelco Dolstra in 2003. But recently, it’s becoming more and more popular and mature enough to run it in production.
  • FHS compliant. Everything is stored in a nix-y way, in /nix/store/. No more /usr/local or /usr/lib/. On top of that, /bin/ only contains sh, /usr/bin only contains env. Most /etc/ configuration files are read-only and they are completely automatically generated from configuration.nix - imagine that!
  • Backup/snapshot replacement. NixOS creates something called generations, which are essentially your system + package configuration snapshots. No user data (i.e. your HOME) is not backed-up in any way. It’s just the system that NixOS is concerned about.
  • A Docker replacement. This is quite a common misconception. It is not and was never meant to substitute docker. Here’s a nice thread if you want to dig deeper.

Summary

Because of these qualities, NixOS is quite different from the standard distributions you may know. It can be hard to start with, but the reward is enormous. NixOS brought a few game-changers to the scene. For one, it’s sturdier, and I’m no longer afraid to try out experimental packages, and upgrade my system and servers I manage. Secondly, I’m pretty sure all my servers are deployed and behave consistently. Thirdly, it’s just so incredibly lovely being able to write my workstation and infrastructure declaratively - as a code.

Oh, and by the way, I’m not here to argue that NixOS is what you want. Although I think NixOS is what you need. NixOS is love!

LAST UPDATE: 2022-03-14