When categorizing Linux distributions, it is often useful to specify which package management system the distribution uses. There are many different package management systems in use, but the two most popular are probably the .deb and .rpm formats. The first comes from Debian and is used by Ubuntu, while the second was developed by RedHat.
NixOS is a Linux distribution with its own unique package manager. The entire operating system, including the kernel, applications, system packages and configuration files, are built by the Nix package manager. The Nix Package Manager uses a declarative system configuration model. This means system configuration items are described in a configuration file, and the OS does everything necessary to make the configuration happen.
If a system admin wants to install a SSH server, then all they need to do is add a line to the configuration to enable that service. NixOS will then download and install OpenSHH, plus generate the relevant configuration files.
Another interesting feature of NixOS is that it stores all its packages in isolation from each other; as a result there are no /bin, /sbin, /lib or /usr directories. All packages are kept in /nix/store instead. This, together with the declarative configuration model, makes upgrading NixOS systems reliable and allows the OS to implement a transactional approach to system management including the ability to roll back upgrades.
The declarative configuration model also makes it easy to reproduce a system configuration on another machine. The admin just copies the configuration file to the new NixOS machine and with one command, the machine will be transformed to use the same kernel, applications, system services, and so on.
To try out NixOS, download the .ISO file from the project’s download page, burn it onto a CD and boot your PC from it. Once booted, you will be presented with a text login prompt. Enter “root” as the username and press ENTER. The NixOS installer doesn’t do any partitioning or formatting, so you need to create and format the partitions manually.
Note: The following commands will erase EVERYTHING on the disk; please proceed with caution.
Type the following:
Where “/dev/sda” is the name of the disk you want to use, in this case the first hard disk in the PC.
In fdisk, type “o” to create an empty partition table. Type “n, p, 1, ENTER, +2G, t, 82” to create a new primary partition of 2Gb to be used as swap space. Now type “n, p, 2, ENTER, ENTER” to create a new primary partition for the NixOS installation. Exit out of fdisk using “w”. If you want to use the free space on the disk without erasing the existing data, then don’t create an empty partition table and modify your partitioning scheme accordingly.
Activate the swap space using:
Now format the second partition:
Now mount the new partition:
Descriptive configuration files are at the heart of NixOS and the Nix Package Manager. Even the installation process needs a configuration file to tell NixOS what to install. To generate a default configuration file type:
Now edit the resulting file using nano:
Find the following lines and remove the “#” sign from the beginning:
- boot.loader.grub.device = “/dev/sda”
- services.openssh.enable = true
- services.xserver.enable = true
- services.xserver.layout = “us”
- services.xserver.desktopManager.kde4.enable = true;
- services.xserver.displayManager.kdm.enable = true;
Exit nano using CTRL-X and start the installation:
Once the installation has completed, reboot your system. You will need to remove the CD or pick the “Boot from hard disk” option if you booted from the optical drive.
The system should boot into the display manager; however, you can’t yet log in as there are no users defined, and root logins aren’t allowed on the desktop. Press CTRL+ALT+F1 to switch to a console.
Now log in as root and add a user. Here is how to create the user “gary”:
You should also change the root password using “passwd”.
Press CTRL+ALT+F7 to get back to the graphical login prompt and log in with the username and password you created above.
NixOS doesn’t include a graphical package manager like Ubuntu or Fedora and all package commands need to be run from the terminal. To list all of the available packages type:
You can use “grep” to find certain packages. Here is how to search for the substring “fire”:
In the list will be the Firefox web browser. To install it use:
The way we added the user and the way we installed Firefox is called imperative management. You execute a command and it happens. However the power of NixOS is in its declarative management. With declarative management, the system administrator tells NixOS what needs to be achieved, and NixOS will ensure that it happens without breaking the system.
For example, to add a user using declarative user management, edit “/etc/nixos/configuration.nix” (as root). Add the following lines at the end of the file, but before the last “}”:
To install a package, add the following line to the configuration.nix file:
To action the new configuration.nix file, use the nixos-rebuild command:
This command does everything necessary to make the configuration happen, including downloading Thunderbird and creating the new user etc.