Posted 5 Jul 2023 (2023-07-05)
So this past month I decided to tackle NixOS once again out of the desire to have my config be managed in an easier and more flexible way than it had been at the time. I had already noticed the limitations of GNU Stow and the fragility of my Arch Linux system; not being able to do what I want with my system the way I want it was really bogging me down. Thankfully I had heard about this cool tool (nix) and distribution built around the tool (NixOS) and had a gander on their web site. A month later I am sold and never want to go back; let me explain why.
So initially I got started with flakes which is a single file for any
project; even whole systems too. In nix there is a thing called a dev-shell.
What this allows you to do is, given a list of dependencies for your project,
reproduce the dependencies for the program to run properly for you and ideally
everyone who uses the file with the project. Anyway, I listed out my
dependencies in the DSL (domain specific language) – yeah, nix is a whole
programming language too but for packing and system configuration – and ran
nix develop
; all the dependencies were pinned to a version of the package
repository, nixpkgs in this case, and the shell was created. From this I could
run everything as it should be ran with 0 issues. It was that easy. I even
checked with other people and it worked the same way for them too. As it should
with reproducability.
Okay so that’s cool – how far can we take this? As it turns out very far.
Then I learned a little bit of the nix language itself – enough that I could
do something with it; even if that something wasn’t very good. I ended up
slowly using the nix shell more and more, then I decided to create a virtual
machine and build my Arch Linux config within it. Surely if it’s really fully
reproducible I should be able to build everything in a virtual environment then
apply it on physical hardware? And sure enough that’s what I did. I installed
the distribution then evaluated the flake with sudo nixos-rebuild switch --flake .
and the entire system was built. All contained within a git
repository too. Something like this in the computing world has been so overdue
but now that it’s here I don’t want to use anything else.
As aforementioned, being able to have a whole system within a single file or git repository then be able to reproduce everything bit for bit (check a hex dump) and have it all just work has been a game changer. When I want to use my laptop after a month or two of not touching it I don’t have to worry about an update potentially breaking it. If it can be reproduced and is broken for me then it’s broken for everyone else.
There’s always going to be upsides and downsides and nix/NixOS is no different:
All in all despite it’s weaknesses I think I will still continue to use it and assert dominance over those who don’t. :)
Oh and just recently I added a flake to this site so everything here should be fully reproducible as it is on my machine. How cool is that? You can find the site source code in the footer.