Experimental package management with Nix and NixOS

Preparing Your System

The first issue you'll face when transitioning to NixOS is which applications to enable. Most users will find all the applications they need in the NixOS repositories. (By the way, there are also some alternative repositories.)

Even though the installer is command-line only, it is surprisingly easy to use. You can use any standard partition scheme. The install manual has examples that you can copy if you don't have any special demands. You do have to know how to handle a partition program. They suggest you use partition labels, which is really useful. You'll need to partition your disks, mount the root partition, boot your new system, and run the nixos-generate-configuration command:

nixos-generate-configuration --root /mnt

Use the manual that is included in the install ISO. The manual looks long and complicated, but it is actually comprehensive and clear. When this command has finished, you will need to edit your configuration.nix file.

configuration.nix

The nixos-generate-configuration command generates two files: configuration.nix and hardware.nix. In most cases, you will do nothing with the hardware file, since the installer has set everything according to the current system you are on. The interesting part is the configuration.nix file. Inside, you will have all the settings you need and the applications you want on the general system.

Starting from the top, the file has the curly brackets that define your environment (Figure 4). You change this setting for extreme cases; on a desktop, leave it alone. Second, you have an import statement that imports the hardware file. You can use this section if you want to break out some of your configuration. Any Nix file that you reference will be added to your configuration.

Figure 4: The top of the configuration.nix file points to the hardware file; you can add your own files for special purposes.

Next, there should be a few lines about your boot loader. The Nix installer detects UEFI and BIOS; don't change the boot loader configuration unless you have very particular circumstances. As you go down the file, most options are clear and follow standards for locale and time zone. When you want to choose a desktop system, however, you are left in the dark – the configuration file has nothing for you.

Fear not! The NixOS website has a very nice interface for looking for options and applications [3]. On this page, you can enter in the application that you want. If you search for Gnome, you get a long list of options (Figure 5). Click on the option you want and the Name given in the list is the name you put in the file. The Gnome entry needs the setting:

Figure 5: Exploring options and applications.
services.xserver.desktopManager.gnome3.enable = 1;

The list of options has more than 10,000 entries! You can use them when you want, but don't let the shear number hold you back. All options you need, initially, are in the original file. You will only need to add a window or desktop manager. Once you have written the file, you can install. The procedure is one script. At the end of the script, you need to set the root password.

The script compiles all programs that are not available in binary form, so it might take a while. You have options for distributing the compile to other computers. If you have problems, you can also choose the --show-trace option to see a diagnostic trace.

After the installation, reboot into your new system.

Updating Applications

At some point a package might require an upgrade. You can use the --upgrade action for this job. More surprising is that you can upgrade to the same versions. As the manual states, this might seem useless. However, you can use it to recompile your current applications to newer libraries and also cut out duplicates of libraries. Enter the following command:

nix-env --upgrade --leq

You can also skip the leq parameter, in which case the command will upgrade everything without optimizing the libraries you use. An upgrade leads to another concern; you may have many versions of any file in your system, which means you'll have many generations to deal with.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • NixOS 22.5 Is Now Available

    The latest release of NixOS with a much-improved package manager and a user-friendly graphical installer.

  • NixOS 21.11 Now Available for Download

    NixOS “Porcupine” has been made available for installation and includes numerous improvements.

  • NixOS

    The innovative NixOS makes it easy to test and deploy new configurations – on the hardware and in the cloud

  • Next Gen Distributions

    With systemd poised to revolutionize the init process, we look at Linux distributions that have left the familiar path, use new approaches and techniques, and are paving the way for the next generation of Linux distros.

  • News

    In the news: EndeavorOS 21.4 Has Arrived; NixOS 21.11 Now Available for Download; KDE Plasma Developers Introduce a Gnome-Like Overview; Rocky Linux 8.5 Now Available with Secure Boot Support; CronRAT Malware Targets Linux Servers; AlmaLinux OS 8.5 Now Available

comments powered by Disqus
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters

Support Our Work

Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.

Learn More

News