biscotty's Workshop

NixOS: The Linux Different

NixOS: The Linux Different
6 min read

NixOS: The Linux Different

Toward NixOS

How different? Really different.

After you've been working with with Linux long enough, you realize that all distributions are basically the same. Different package managers and different package repositories, different kernel configurations, different default desktop environments, but given a command line it is almost trivial to move from one distro to another.

Not so with NixOS. Want to see what software is installed? You won't find anything in /usr/bin, or any other typical bin or opt directory. Want to add hosts to /etc/hosts? That file, indeed everything in /etc, turns out to be read-only, even to root. Add a user with useradd? Nope. Install some software in a gui "App Store", or even with a command like apt install? These don't exist. In fact, many of your basic system administration skills are useless with NixOS without having access to the basics such as the FHS and the ability to edit configuration files. But, don't be sad, your Linux skills are still important, because...

It's still Linux

NixOS is, never-the-less, GNU/Linux just as much as is Fedora or Debian. It runs a Linux kernel with a GNU api. It has a large package repository, the largest of any, in fact. It even uses systemd. You can add any software that runs on Linux, and to an ordinary user, the daily experience is the same as on any other distro. They might remark how stable and snappy it is, but their day to day workflow would not be different.

Under the hood, though, everything is different on a fundamental level. NixOS has a learning curve more similar to learning a new operating system than learning a new ordinary Linux distribution. Which leads to an obvious question: why bother?

I'll be looking at many reasons, but one is that, once the Nix way is grokked, all of these admin tasks I mentioned become much simpler and straight-forward, more robust, easier to rollback, and fully reproducible. I guess that's more than one reason.

Getting a little personal

For me, NixOS is in a way why I turned to Linux decades ago. When Windows first came out, I felt like a veil had been drawn over the OS, which then became hidden and mysterious. Apple computers seemed even worse in this aspect. For some types of work, the graphical user interface was a great step forward. But for other things, the gui just obscured the underlying workings of the computer and made many things more difficult. With every system crash, I wanted to understand what was really going on so I could fix it. Then I discovered Linux, and more specifically Slackware, which uses a terminal and vim for all administrative tasks. The ability to understand exactly what a computer is doing, to configure it with text files, to install, and if necessary, build, software from the command line, was just what I was looking for. Even when I started using other distros, I never take more than a quick glance at their graphical admin tools like app stores and such.

But, as experienced Linux users know, there are many issues which arise over time on any Linux system, such as software upgrades which create library version conflicts, problems which are made worse on shared systems. Cruft accumulates over time as uninstalls are rarely clean. If you install and uninstall many programs, after a certain amount of time, it is difficult to be sure exactly what lingers in /etc, /usr/share, or anywhere else, for that matter. After a year of installing, uninstalling and configuring software, how can you be sure what is actually there? And when your new computer arrives, or you finally decide to to a clean install instead of a version upgrade, how much effort will it take to set it up exactly how you like it?

Enter NixOS, where I can declare the entire operating system with text files! I can write down what I want, and know that that will be all there is on my system, despite what may have been there before. I can, for example, simply grep my configs to see everything installed and all configurations, without needing a special package manager tool. In fact, with NixOS, nothing is every really installed, upgraded, or uninstalled, not in the traditional sense anyway. Any of these activities generates a brand, spankin' new system which entirely replaces the old one.

Embrace the difference

Here be dragons, but they are auspicious Chinese dragons, not scary English ones. The singular power of NixOS lies in the differences, so they are worth exploring. They involve ideas such as declarative, functional programming vs imperative, procedural programming, graphs vs stacks, immutable systems, atomic upgrades and containerized environments. Also, Nix/NixOS isn't just one thing, it is a programming language (Nix), package manager (Nix), repository (nixpkgs), and operating system (NixOS).

Exploring all these topics would be overwhelming in one article, so it is my intention to write an occasional series on each. None of these will be tutorials, rather they are intended as an introduction to the ideas necessary to understanding NixOS. As a practical matter, Nix the package manager and language can be installed on any computer and be experimented with, or even used as a primary package manager for your current system. NixOS also runs nicely in a virtual machine. To learn NixOS you'll need to get your hands dirty, and for me at least, getting used to NixOS and configuring my system from the comfort of Fedora made the eventual switch to hardware completely painless, as I just needed to copy my configs to the new partition and build it, not repeat my work. Don't rush, enjoy the learning.

NixOS is not for everyone. The imperative paradigm has worked reasonably well for decades, and has the virtue of familiarity, so there is no imperative to change ;-). But if, like me, you prize stability, clarity, and simplicity, if you find change and learning new ways to be stimulating, and if you know that the most interesting things in life are on roads less traveled, you will be delighted by NixOS.