Installing NixOS

Posted on January 18, 2019 by John Duhamel


NixOS is a Linux distribution that can be fully configured using a functional configuration language called Nix. There are several advantages to this approach. NixOS stores a snapshot of the system each time you rebuild the configuration, making it easy to revert to a previous good state in case you brick your system.

Additionally, it’s easy to share configurations on multiple workstations, greatly reducing the burden of creating new hosts. For this reason, it’s convenient to experiment with new configurations using VirtualBox. When you feel ready, it’s reletively easy to port your configuration to your actual hardware making a small set of documented changes.

Start NixOS

In this post I’m using VirtualBox as an installation platform. This should be sufficient to create a base image that I’ll be able to port to my primary desktop.

First, create a new virtaul machine and mount the ISO image.

Now, boot into NixOS. If everything goes well, you should get to a root shell with network access. If you’re following along on a laptop and need to connect using wifi, run the nmtui utility to connect.

Create Partitions

Next you’ll need to create some partitions. You’ll modify this when you port your config to other systems, so a single partition will work fine.

$ parted /dev/sda -- mklabel gpt
$ parted /dev/sda -- mkpart primary 1MiB 100%
$ mkfs.ext4 -L nixos /dev/sda1

Install NixOS

Now, mount your new filesystem and proceed with the installation. You’ll need to edit /mnt/etc/nixos/configuration.nix and add the following line:

  boot.loader.grub.device = "/dev/sda";
$ mount /dev/sda1 /mnt
$ nixos-generate-config --root /mnt
$ vim /mnt/etc/nixos/configuration.nix
  boot.loader.grub.device = "/dev/sda";
$ nixos-install

Now it’s time to reboot your system. If you did it correctly you’ll see a grub menu like this.

Install Vim

Once you reboot your system, you may notice that some tools are missing. The first obvious one that stuck out for me was that vim was not installed. In order to install it, add the following to your config:


  environment.systemPackages = with pkgs; [

  environment.variables.EDITOR = "vim";
$ nixos-rebuild switch

Add a User

Note: We do this at the command line rather than my nix config. This approach allows you to decouple system-dependent variables from your NixOS configuration. Some users may prefer to hardcode these in the nix config.

$ useradd -m -G wheel <user>
$ passwd <user>

Also, you may wish to enable passwordless sudo.


  security.sudo.enable = true;
  security.sudo.wheelNeedsPassword = false;
$ nixos-rebuild switch


Now you have a very basic NixoS installation. You may wish to read my next post as well, where I set up i3 and install a few appications to make the install more usable.