Months ago I once took a dive into NixOS and decided then it wasn’t really for me. Now I’m revisiting it and I wanted to talk about my previous experience with it then, and what I am trying out now.

I have a wide array of computers, but my primary two are my ThinkPad T440, and my custom-rig desktop, both running Linux Arch-based OSes (Manjaro). Both have different configs (different displays, different drives, different video/CPU drivers), but mostly have the same packages installed. For a time I was using Manjaro comfortably, but I only had recently learned about NixOS fairly late into the game from a few friends.

NixOS, an OS based entirely around the Nix package manager (similar to Guix), employs the idea that a single script file should be able to reproduce successfully a bootable operating system.

At least, that’s my understanding of it. A rather functional operating system you can say; give Nix a file, it gives you back that desired operating system every time.

My first run-ins with NixOS were… not good.

NixOS Step 1: Actually Installing It

This part I feel is where users may struggle with NixOS at first. And it is absolutely where I struggled, but in retrospect, it’s not as hard now, and definitely not as hard as Gentoo.

I’ve been too used to easy-to-use GUI installers that suddenly when it came to properly formatting my disks from parted and using mkfs.ext4 I started to feel a little uneasy. In a few commands, my previous OS was gone. What little guidance I had with the NixOS manual was all I had now moving on.

Setting up the primary NixOS configuration file was now the next step. If you’re on Linux, you are probably used to config files and editing things, but learning the Nix language is something else. Defining your system packages, your window manager, and many other things, but this was the easy part for me at the time.

The harder part was defining which disks would get used in the process. I screwed up on this part a lot, and many times, could not boot into the newly-installed OS because of bad configuration. I followed the manual as much as I could but found it tricky to get it working for UEFI. It took many several attempts before I got it right, and afterwards came the next part of my new-found NixOS life:

Step 2: Actually Using It

A big thing with NixOS is the ability to install packages and rebuild your system and switch to it immediately. Rolling back packages and versions of your configuration is also a thing, in case you break something. NixOS also looks to create a layer of immutability so that it is easier to reason about packages and managed files, and at times was something I was struggling with myself.

I guess a big thing when your system is called NixOS is the number of different moving parts all called or using the string nix. The comforts of pacman left and wasn’t coming back anytime soon, so thus began a large research phase of how do I start “getting good” at NixOS.

For the most part, everything is done through nix-env which allows you to query Nix stores and your own system. If I need to search for something like xbacklight, a utility to manage brightness of devices, then you need only type in nix-env -qa xbacklight. Once you find a package you need, you can append it to your environment.systemPackages.

Except that sometimes isn’t… quite good enough for environment.systemPackages. Some packages may be part of another package space, so for xbacklight, it’s actually xorg.xbacklight. I only found this out after some Googling and looking up on the Nix package web search.

nix-env -i <pkg> will also install a package into your current NixOS system, but it will not be added to your configuration. This is in turn something you have to do yourself, and probably should, so you can reproduce it later in a nixos-rebuild call. nix-env is good for the short-term but nixos-rebuild is really the end-goal for NixOS.

Later on, you may want to start adding some files to your system for configuring programs, a la Emacs or Vim, but this is where NixOS will blur the line. In turn, a lot of NixOS power users switch from depending on the NixOS config, to then use something called Home Manager to manage their NixOS userspaces. I didn’t really get this at the start, because if it’s so vital, why isn’t it included? I wanted to try and like the idea behind it, but it seems like such a hack that it may not work widespread across all user needs. I tried avoiding this.

There are ways to bind certain NixOS files, but once you do that, they become immutable by NixOS. Certain times, and it may be silly, but my Emacs would need to re-write it’s configuration files. With NixOS, it was incapable of doing so, and I was stuck looking for another solution. The system space can be immutable, but for a reasonable userspace, I don’t really think immutable works there very well?

Step 3: Eventually Giving Up

I later on lost hope after a few weeks of trialing out NixOS on both my Thinkpad and my desktop. Some of the quirks of NixOS I enjoyed, but other times I found it a struggle, and a constant Google search of doing things the NixOS way. Applications would be out of date, and for me to get them up to date would be a search I often times didn’t want to deal with. It seemed very community-based, and I was unsure of it’s progress and success.

So I went back to Manjaro. But only for a brief period of time.

Step 4: Coming Back

After NixOS’s recent 19.09 release, I decided to give it a tiny whirl on my Thinkpad. Burned the image, ran the live installer, and gave it another try using my previous configuration.

This time it didn’t take me as many tries to get it right. I re-modified some of my packages that were apparently marked as broken (rest in peace sonic-pi) from the GitHub NixOS community, removed some things, modified bits which gave me errors during nixos-install --show-trace. Admittedly, it took me probably two nights worth of work: one being I was not watching the install one night hanging with friends, saw it spat an error way too late, and then restarted the install the next day after correcting issues.

Step 5: Second Time’s A Charm

So here I am writing this post from the comforts of a basic NixOS install, using i3-wm and vim and git to write this blog piece. I still have some config’ing to do but much of my setup is based on half nixos-rebuild and half cping files to the right places.

One half of this is just NixOS invoking nix to get the packages, files, drivers, whatever else and putting them in the right places. This is done mostly through automagic configuration, but I’ve said enough about that honestly. Not much has changed.

The second half is me using direct copy-file processes for copying my configurations over into the right places. I don’t really trust Home Manager to do everything I need for me automatically, so the next best step is just saving my dotfiles to a git repo and copying things over when I do a full rebuild. I can separate NixOS configs but keep the dotfiles the same across systems. It’s a little bit more work, but I think for the time being it’s alright.

To some parts where I think I can improve, I might just use Racket to do a bit of the hacking instead of Makefiles. I prefer using Racket for fun where I can, since it’s always a joy to play with.

Hopefully I won’t be writing about leaving NixOS in a week.