NIXOS
Build your own distro with NixOS
“Why, I do declare!” Matt Holder proclaims as he builds his very own operating system, using just an ISO file and declarative text files…
Credit: https://nixos.org
OUR EXPERT
Matt Holder has been a fan of the open source methodology for over two decades and uses Linux and other tools where possible. In his spare time, he enjoys listening to music and reading.
We’re continuing our look at next-gen Linux distro paradigms, moving on from our dive into the Fedora Silverblue (LXF299) immutable system to NixOS, another example of an OS that uses modern techniques to make distros as reliable and secure as possible. This operating system handles things very differently and also uses a lot of the same techniques as the tools that can be used when utilising the infrastructure as code methodology.
NixOS centres around the Nix package manager, which is used to build applications that are installed in a very different way from what we’re used to. Applications can be installed on a per-user basis, or for every user. When installed, each app is stored in its own directory and multiple versions of the same application can be installed. Each directory contains all of the application’s dependencies and, again, multiple versions can be installed across the system. Applications installed or upgraded using this system are atomic, meaning that the rest of the system will not be broken if an upgrade or installation fails. Should a bug be found in a version of software, it can be rolled back, due to the old version not being deleted straight away. Garbage collection is also something that is built into the Nix package manager and old versions can be deleted periodically. Automatic updates are also easy to configure with the system.
The first stage of the NixOS installer.
MANUALLY ADDING AND REMOVING PACKAGES
While the idea of NixOS is to be able to use a declaration file to ensure the configuration of the OS is as expected, it is also possible to manually install and uninstall packages. This can be considered to be incredibly similar to using apt on a Debian or Ubuntu system and dnf on a Fedora system.
To search for a package, either use the website in the Quick Tip (right) or perform a search with nix search
. Packages can be installed on a per user basis. For systemwide installation, the configuration file method should be used.
To install for the current user, use nix-env -i . Uninstalling packages can also be carried out at the command line, and this can be done with nix-env --uninstall . Any packages installed using the commands described in this boxout can be viewed using nix-env --query
--installed . Automatic updates are enabled by default, but can be run using two commands. First of all, update the channel with nix-channel --update and then run the update for the logged-in user with nix-env -u . To update packages for all users, run nixos-rebuild --upgrade switch .
Methods described in this boxout should only be used for testing. If these methods are used, then the benefits of a declarative system are greatly diminished.