Installing NixOS

{% include toc %}

Get NixOS on the USB stick

Formatting the USB stick: 1. Find out the device:

  1. Unmount
  1. Format to FAT32
  1. Detach and reattach
  2. Copy NixOS on the USB

Install NixOS

My laptop is a Lenovo Thinkpad T440s and I’ve followed (mostly) the set of instructions on Chris Martin’s blog.

Booting and partitioning

First of all, I had to switch to only using UEFI in the boot menu and then boot from the USB stick. I wanted to wipe the whole disk and reinstall NixOS on an encrypted partition. The NixOS installer does not (yet!) have a graphical user interface for partitioning, but what I wanted to do is fairly straightforward to achieve using fdisk. I followed the advice posted on StackOverflow1 and ended up creating the following partition table:

The LVM device will contain the OS and will be partitioned into the root folder / and the swap.

Setting up the encryption, LVM groups and volumes

Let’s move on to encrypting the device where the OS will actually live, i.e. /dev/sda3. I am here following the instructions reported on the NixOS installation instructions. The first command encrypts /dev/sda3 and will prompt you to insert a password, the second command opens the encrypted partition:

OK, great! Time to make space for / and the swap:

and to format:

At this point, launching fdisk -l you will see the following output (or at least I do!):

Get the installation going!

Let’s mount the disks and volumes to /mnt:

and activate the swap:

NixOS declaratively defines the configuration of the system. The starting point is to run the following:

that generates hardware-configuration.nix (do not touch) and configuration.nix in the directory /mnt/etc/nixos. My configuration.nix is available on GitHub and I can just clone the repo with and populate the /mnt/etc/nixos directory with the contents of the repo. This will not only configure the system as I like, but also install all the software that I need in one go. Once the configuration.nix is all set run:

and reboot when the process is done.

First login

Login as root user when the system reboots and add the 17.03 channel:

Add whatever you need to configuration.nix and rebuild your system:

Moreover, the user that was created in the configuration.nix file does not have a password set! Let’s do it now:

You can now login as a normal user, instead as root. The system is now ready for use!

  1. Thanks to Radovan Bast for the tip.