Linux Distros

A Review of NixOS

Most reviews go over desktop tools and default tools, but such reviews are not very useful for describing NixOS, as the power of NixOS lies elsewhere. People who choose NixOS must be willing to do their own partitioning, and you will not be doing them any favours by telling them the default desktop manager can suit their needs.

With that said, if you can follow the NixOS manual, you will be fine. You can choose a default desktop environment if you want, but make sure you are comfortable with the command line and can edit a text file for configuration tasks.

A powerful configuration

The ability to configure NixOS is both an advantage and a challenge. Traditional package managers bring the package into the established LSB structure of the files. In NixOS, the installer puts the files in the store with a hash before it. This convention may sound complicated, but it enables many features.

When you install a program, the package manager prepares a directory with all files and adds links to the positions where they should be placed. It also copies the dependencies in the same directory and links them in the structure. To track which programs need which dependencies, a profile is used. With the store and the profiles, you can have many different combinations of packages.

You can also switch over with a few commands, and rolling back is super easy: just pick the old generation at the next reboot. If you are playing around with configurations, you will end up with many generations. However, you can use nix-collect-garbage -d to clear the boot partition (although you must them run the nixos-rebuild command!).

Handling revisions

In the Nix Store, where all your software is stored, you have one file for every executable. At first glance, this convention appears no different from those adopted by other systems; however, there is a big difference: Every time you upgrade, a new binary is added and then linked to your profile, which can very quickly lead to wasted disk space.

To address this issue, there is another garbage collection option, which is the same program that is used with the entire system. If you need old revisions for only a short test period, then you can set systemctl to run at a regular interval. Furthermore, you can save disk space by using the ‘nix-store –optimise’ command, which finds identical files in the store and links the files to that one file.

Setting up development environments

At first, it seems hard to develop software with this system. In fact, you can start a shell with a specific development environment each time. When you pick an environment, nix-shell will install the environment you need so that you can start a specific environment for some odd language you never use or create a file that collects everything you normally need.

Docker and other clouds

NixOS is an operating system, and Nix is a package manager. The two work together to provide a straightforward and reproducible configuration process. In other words, if you create a full configuration file that covers all your needs, then you can use that for your next machine.

The installation procedure starts by detecting hardware. In the second step, you define your environment and system packages using the configuration.nix file. Once you have the correct content in the file, the installer will recreate the same system when you use it on a second machine.

This functionality is useful because, for regular systems, a new disk needs only the file to rebuild your system (in addition to your user file backup, of course). Furthermore, for cloud computing, you have an even bigger advantage: While the files you need to write for a docker image are really long, the corresponding file for NixOS is short and easy to move between systems. In addition, you can use the import function to create special nix files for your odd configurations and import them into your config.

Appimage, snap and flatpak

While NixOS has many brilliant ways to run your applications and separate them from each other, a lot of software is delivered in other ways. Appimages and Flatpak are easy to use to distribute packages. Fortunately, NixOS has packages for handling these formats, and you can install these packages to run your favourite AppImages and Flatpaks. You can define the packages in your configuration.nix file and have them available when you need them.

Conclusion

NixOs seems intimidating because it has no graphical installer and you need to create a configuration file. However, only in NixOS do you set the same values in both cases. To back up a NixOS system, not including the user files, only a single file is needed. With this file, the system recreates the packages and settings. Furthermore, NixOS provides a built-in method for running a shell in a specific environment: Just use the same type of file! In the file default.nix, you can define all your libraries and dependencies and then run nix-shell in that directory.

This system has a lot of potential. Try it out: You can start with your own distribution and the nix package manager.

About the author

Mats Tage Axelsson

I am a freelance writer for Linux magazines. I enjoy finding out what is possible under Linux and how we can all chip in to improve it. I also cover renewable energy and the new way the grid operates. You can find more of my writing on my blog.