home | section main page

You should use NixOS

Table of Contents

1. Introduction

NixOS is a reproducible, scalable operating system that is used in server infrastructure. This month, I decided to torture myself and run it on a personal computing machine.

Just kidding, it's really good, and currently the only operating system that can do what NixOS does is GNU Guix. What's particularly interesting is that when GNU and Linux people say, "Look! Finally something that only Linux can do well!", there's usually some tool out there that can get most of the behavior out of MacOS and Windows, or maybe there's even a "better" version of it on those two operating systems. However, NixOS and Guix are truly unique and their usage truly cannot be replicated on either of the two systems. I will talk about NixOS in particular because that is the operating system I currently use.

2. So What's the Pitch?

When you write a configuration for NixOS, it works forever until the packages stop being hosted, meaning as long as the NixOS team exists, your particular version of NixOS, running your particular configuration, will always work in the same way. It will even work the same way across multiple computers, given you don't put in too much hardware-specific configuration into your configuration.nix file. Interestingly enough, it is possible to make sure that network copying errors don't happen, and make the system almost completely deterministic. Essentially, you can define your operating system as a function that takes in inputs and outputs, and then specify those inputs in a specific way, which then allows you to ensure the reproducibility of your environment.

On top of that, it is possible to roll back your configuration. That is, you can reset the state of your computer to a previous version, as previous versions or generations are cached until they are disposed of manually. This means that the state of your system is extremely persistent.

You can see why this might be used in industry for mass deploying servers, and you might even understand why one might use this type of system for docker containers, but why on earth would someone run it as a personal machine? Well, there are a couple of good reasons to do so:

  1. You like how your computer operates.
  2. You don't want that way of operating to change, randomly.
  3. You want to reproduce how you operate on any machine that you will own in the future.
  4. You want features like backups to be highly integrated into the operating system.

You can see how this system is genuinely so much better than anything that exists, because if you're looking for the above, NixOS is for you!

3. Sounds Great! Any Issues?

Although the language itself is documented decently well, nix is not a very good language to program in and the documentation on some of the library functions/builtins are not very good. Also, the documentation for stuff like home-manager (if you want to manage your home directory in a declarative, reproducible way) is not very good. It's pretty possible to learn, though, and if you get it working once, it works forever.

3.1. Building from Source

Because of how packages are managed on NixOS, building a package that's not from the repositories is a pain. Additionally, to my knowledge NixOS has no equivalent of Gentoo USE flags, or if they do exist, they are confusing and undocumented, so you might have to fork the standard NixOS repositories yourself.

3.2. Flakes

Flakes are an initially confusing part of NixOS especially since there isn't any documentation on them. They essentially allow you to specify inputs into a given system, and they return a declarative state. This is useful because flakes allow you to "pin" the inputs (make it so that the inputs are all compared to their hashes such that they never change), which makes the outputs completely deterministic given the code run is also deterministic (always the case in pure flakes, and NixOS uses a functional programming model that eliminates side-effects). I recommend using a flake in order to define your system instead of the default configuration.nix file.

4. GNU Guix

There is yet another system out there that I believe is technically better than NixOS at a lot of things, yet I also believe it to be hard to use in practice, and that is GNU Guix. GNU Guix has the same operating system model except everything is written in scheme. This is beneficial because programs like emacs and Nyxt integrate well with the package manager, and the init system is GNU Shepherd which is almost completely configured in scheme. This is a notable operating system although it is somewhat confusing and has less documentation than NixOS.

5. Conclusion

Running this operating system for me has genuinely felt like running an alien system from 10 years in the future. It is a shame that it does not get widespread adoption as it is clearly one of the most effective systems that exists, barring the fact that operating systems like these may need more developers.

Copyright © 2024 Preston Pan