Falling in love with NixOS

Gauthier POGAM — LE MONTAGNER
4 min readMay 14, 2017

--

I discovered Linux 6 years ago, with Ubuntu, and started to use it 5 years ago as my main operating system and since, I spend hours learning about my system and tweaking it for fun.

From Ubuntu to Exherbo, I tried various package manager and delivery policy. But all were kinda the same : your package manager download and install a package in your OS tree and you can use it. Everything is messed everywhere, updates are simply uninstall of the old version and installation of the new one without more protection of your system and have fun when something breaks… Most of the time, the package manager keep the old version of the package on your system but it doesn’t mean you’re safe, sometimes the wrong new version can have broken dependencies or damage your configuration or you system in a way that your best solution is to re-install if you don’t have hours to spend to fix your system. But that’s okay, after all, all systems work like this, right

Yes … Wait … No !

What ? Is there a magic solution that would keep my system safe and would allow me to go run a previous version of my system if my update fails ? A system that keeps my old configuration separated from the new one in case the later is broken ? I want it !

Yes it does ! Yes, this dream exists ! And it’s called NixOS !

NixOS is a Linux distribution featuring Nix, a Purely Functional Package Manager. To quote the official website, Nix is …

… a powerful package manager for Linux and other Unix systems that makes package management reliable and reproducible. It provides atomic upgrades and rollbacks, side-by-side installation of multiple versions of a package, multi-user package management and easy setup of build environments.

Okay, that looks impressive, but … What does it mean ?

NixOS use a particular file system architecture : instead of the classic “/etc” for configuration and “/usr” for system binaries, libraries and shared content, all packages and configurations are stored in the Nix store (/nix/store). Each package is installed in a folder named like “71kzzfl4ryiw97pk9ld7mvv6871p3vid-konsole-16.12.2”. Linking between packages is then done with symlinks so the package is linked only to what it needs (libraries, other binaries or shared or temporary resources).

With this naming system, you can have as many version of a package as you want and linking between them is dynamically done depending of what the package needs. And here comes atomic upgrades ! As each version is on its own folder and are cleaned only when you ask for or when no other packages us it, you can easily rollback to a previous version of a software and the new version will be installed in its own folder, not erasing the previous version. This also mean that your configuration in /etc is safe, it’ll not be destroyed between 2 updates !

This nice package management also comes with a really nice feature : profiles. Profiles are a set of packages installed for a system or a user. As usual, the system profile will be managed by your root user and will contains all the software available for all users and necessary for your system to work, similarly to other distributions. But, the new thing here is users profiles. User profiles allow any user to install its own packages and this packages will be available only for his profile. Like that, each user is free to install what he wants, without root access and without messing up the whole system ! Really nice, right ?

But it’s not finished … I didn’t told you about the best feature of NixOS : its declarative configuration system ! Declarative configuration allows you to configure your whole system just with one, short, file : “/etc/nixos/configuration.nix”. In this file, you set options for your system which allow you to build your system, by selecting your graphical environment, your network manager, which services are enabled, etc…, all of this in one unique file.

Enabling Plasma 5 on a laptop just needs six lines for example :

# Enable the X11 windowing system.
services.xserver.enable = true;
services.xserver.layout = “fr”;

# Enable Touchpad support
services.xserver.synaptics.enable = true;
services.xserver.synaptics.twoFingerScroll = true;

# Enable the KDE Desktop Environment.
services.xserver.displayManager.sddm.enable = true;
services.xserver.desktopManager.plasma5.enable = true;

And … it’s enough ! Just add this lines to your configuration, and Plasma 5 will be ready on your computer ! No more missing packages, no more long configurations or services management, NixOS do everything to simplify your life and to help you focusing on what you really want to do and get ride of sys-admin. But this also bring flexibility : you just have to change this file to enable new features or customize your system, many options are available to let you setting up exactly what you need, but still easily.

If you want to see a complete configuration, I posted mine.

I can’t cover all nice features of NixOS and how helpful they are, but I highly encourage you to download it and give it a try ! The manual contains all information you need to know to install, run and manage a NixOS system. I hope you’ll like it ! ;)

--

--