NixOS after a month or two

Otto P
7 min readNov 27, 2021

--

I have been a Linux user for almost a year and a half now. I have used many distributions in this time, but NixOS is probably the most unique out of all the distributions I have ever used. I have been on it for a month or two by now and wish to write about my experiences so far.

So what is NixOS?

With most Linux distributions, there isn’t too much of a difference as they follow standard methodology in how they operate. NixOS, however, throws all of this away and does its own thing.

Nix

The whole basis for NixOS is their package manager, which is called Nix. On typical package managers, you use a command on the terminal to install software. While NixOS has commands you can use to install software, the primary approach of installing software is to do it declaratively. In practice, this means that you write down the software you want to install in a central configuration file and Nix will install them for you. You can also configure the packages this way. Want to install a specific version? Possible. Want to change the configuration of something like DWM? Possible. All in the same file.

Furthermore, Nix also considers the packages independently, so dependency conflicts can be avoided. This and the declarative configuration also allow Nix to provide rollbacks, so if you break something, you can just go back to your previous snapshot of Nix and fix up your config file. Nix, however, is not restricted to NixOS. You can install it on any Linux distro and even MacOS.

NixOS

NixOS takes this concept of declarative configuration and implements it outside of the package manager as well. Not only can you manage your packages in a declarative file, but you can also manage all of your system settings in it.

As opposed to most distributions, installed software is not stored in standard directories, but instead they are stored in a common /nix/store directory, which allows for some interesting possibilities when it comes to building a NixOS system.

You can also install specific software only for the user, although the default approach for this is not declarative. However, you can change this. With a tool called Home Manager, you can install software in your user’s home declaratively and you can also manage home configs in that one file.

Furthermore, you can also configure home manager inside your central configuration file, so you can have everything in one place.

How about my experience?

When I initially set up my NixOS installation, it was done in a pretty typical way. I had one file managing system stuff, but still managed my home configuration files manually. Despite this, the declarative approach was nice. Installing software felt very nice from the beginning and the rollbacks were extremely helpful in troubleshooting when I broke my configuration a few times.

Of course managing my system declaratively wasn’t enough. I also wanted to do the same with my configuration files. At this point I discovered home manager and set it up. Now everything was done declaratively.

Difficulty and documentation

All of the above is very cool, but getting there was far from easy. Coming from more standard distributions, I am quite familiar with using the Arch and Gentoo Wiki as resources to help me. This wiki, just like the Arch and Gentoo ones, is community maintained. However, it is not currently nearly as mature. I will likely start contributing to it myself as well since I have seen some aspects that could be improved. The wiki pages don’t really always cover how to implement something or are not detailed enough for me to be able to follow them. There is also an official manual, but that only covers the very basics of NixOS, so it was not very useful beyond the installation guide.

The community

Luckily enough, the community is great. Due to the wiki not being very thorough in some areas, I have had to ask questions. For this, I mainly chose the Matrix chat for Nix/NixOS, although I am also in the Discord server. At no point has the community shown any toxicity towards me and they have always been very helpful in helping me to find a solution to whatever I have wanted to do.

The community interaction is mostly limited to questions, though, so I would love some more casual interaction, but it’s a great community regardless.

At the end of the day, setting things up to a smooth state took me many days and many hours during each of those days, but I had finally set up a system.

The immutable root adventure

However, I didn’t stop there. I mentioned earlier that the NixOS approach allows for doing some cool things with a NixOS system. Beyond the obvious benefits of Nix, there is also the concept of an immutable root. This is by no means limited to NixOS as distributions like Fedora Silverblue and OpenSuse MicroOS exist. However, Fedora Silverblue mainly utilizes Flatpak and for the non-Flatpak software installs, a system reboot is needed to implement the new snapshot. MicroOS is not even designed for desktop use, but for running containers, so everything runs inside containers. Neither of these are what I would want from my desktop system. Flatpak software is too separated from my system and thus creates inconveniences. Rebooting my system all the time would not be too nice either. However, NixOS allows me to create an immutable root without these problems.

Earlier I mentioned that all of the software and such is installed inside the Nix store. Everything is also managed in a single configuration file. This means that you only need to keep a few directories persistent and still store everything that matters. The rest of the root partition can be wiped. There are many ways to create an immutable root in NixOS, but I chose to use the tmpfs as root method, which I found in Elis Hirwing’s blog. This means that you don’t have a root partition on your disk, but instead run the root inside tmpfs in your memory. I simply have a /boot and /nix partition. Inside the /nix partition, I have a persist directory to hold my persistent directories, such as /home, /etc/nixos (where the system configs are stored), and a few more important directories and files. To manage this persistence, we can use bind mounts. I opted to use a module called impermanence, which allows me to easily define the persistent directories and files cleanly inside my configuration file.

In changing my system to be this way, I ended up wiping my disk. So I did the install process following the tmpfs as root blog in accordance with my own needs and implemented the impermanence module. Afterwards, I just cloned my previous configs from my personal Gitea server and my system was mostly set up almost immediately. I also had to clone the Firefox configs that I have stored separately on the same Gitea server. The browser’s files change too much for me to want to manage them inside of home manager, but having some sort of a backup of them is nice since I can get back to an usable state quickly this way.

Beyond this, it was just a matter of signing into some apps like Steam and installing any games I wanted to install, which amounts to 3 or so small games.

The system now worked perfectly fine with an immutable root that gets wiped during every boot, getting rid of any garbage files that get made.

Since then, I have continued with a very nice to use system and struggled on a few occasions when trying to configure new things, but eventually have always been able to get things to work.

Config organization

NixOS also provides a great deal of freedom with how to organize my configuration. Previously I used the default of one configuration file for the system and a separate home manager in my home directory, but during the past few days I have changed things up a little. I moved my home manager configuration into a module in my central configuration. I then split up this configuration into a few files and now the main configuration file only imports a few organized files. This should make it much easier to modify a particular aspect of my installation since the configs are now clearly split between the different aspects of my system. This is how my configuration directory looks currently:

Conclusions

In conclusion, NixOS has been a very difficult distribution to learn and use. However, it has also been greatly rewarding for me and I truly love what it offers to me as an user. Thanks to it, I have been able to create a very interesting setup that works in a largely optimal way for me.

Also I am very grateful to the NixOS community for how helpful they have been in getting me started within NixOS.

--

--

Otto P

A new software engineering student. I write about technology, software, FOSS and Linux. I am by no means a professional, so I just hope to enjoy some writing.