Nix can set up your whole operating system

 · 4 min · torgeir

I installed NixOS on my personal computer. Here are some thoughts, three months in.

Nix Nixos

This post is part of the Series: Nix can

Starting mid-October 2023, I made a decision to try installing NixOS on a spare SSD I had laying around, on my personal computer at home.

This is three months in, and I kinda like it. Parts of it, at least. And what were my impressions on Nix after a few days pretty much stuck with me;

The goals of Nix are ambitious, and the ideas behind it are what I’d characterize as approaching developer nirvana; Reproducibility. Reliability. Atomic upgrades. Atomic rollbacks. Upgrades that don’t affect unrelated functionality. Declarative configuration.

I’m super exited for the idea of declaratively managing whole systems like this. Being able to configure everything from disk partitioning to what kernel and services should be running, to what apps and configuration files you have installed, in a way that is reproducible across machines, or in case of a disk crash (assuming you have backups of your content, of course), makes one feel incredibly powerful.

One thing I personally find really fascinating, is the ability to roll back after experimenting with all these changes, be it kernel versions through system configuration in general.

With all things being symlinked into place, with links pointing to one central folder - the /nix/store/, where everything is installed, depending on what configuration you provide - the matter of rolling back is simply restoring all the previous symlinks, and discarding the new. Which is something that this system does for you automatically if you ask it to.

NixOS will roll back your whole operating system, with you simply choosing a previous boot entry from grub or systemd-boot menu. Assuming you didn’t mess up grub or systemd-boot, that is.

Plain Nix will roll back your system configuration, even while the system is running. If, say, you messed up a service configuration or the home-manager config. It is all a matter of running a single command.

Ever installed something like KDE, changed your mind, moved on to install Gnome, then tried to go back and messed everything up? With Nix its as simple as flicking a switch for what desktop environment you’d like. Change your mind? Flick it back. Reboot and it just works™!

It’s not all sunshine and rainbows, though. These are hard problems, so expect some complexity. The learning curve is steep, the documentation is dense and scattered across a number of different resources. Many of them third party resources, that really attempt to alleviate the situation, but also contribute to it being spread out. This makes it hard to navigate and get a sense for how all of this stuff actually works, how components work together, and who is responsible for what.

I regularly find myself looking at code to get a hold on how to use things, and I spent way too much time trying to do what I would expect was simple things. Both looking at language features and features of popular modules. Like e.g. passing dependencies to your own home-manager modules. Which ends up being you pass home-manager.extraSpecialArgs = { inherit inputs; }; - I mean, what the actual.. And this is not meant to bash on home-manager, but I find this a recurring challange across the ecosystem, also because this whole system and the nix language itself is so different from other languages you might be used to.

Here are a few resources I wish I would have spent more time with earlier in the process.

From what I understand neither of these are part of the official documentation. I might be mistaken.

Here’s a few more great blog posts

While I repeaedly feel like I’m starting to grok how the different parts of the ecosystem comes together and how Nix works on an intuitive level, reading stuff like Jade’s recent post on flakes vs non-flake way of nix makes me wonder if I have actually understood anything at all.

Anyways, here’s the repo containing the setup for a linux workstation running NixOS with Sway (and a bunch of other stuff I have gathered over the years, ported to the nix way)

https://github.com/torgeir/nix

Have fun! 📦