Jump to content

Drift/Setting up a new NixOS host

From Programvareverkstedet

The first step in setting up a new NixOS host is well, installing NixOS. This however varies based upon whether or not you have physical access to the device, and if it already has an OS installed already. For this guide we will assume you already have a system with Nix installed. If you do not have a system with Nix, you can use one of PVV machines already with NixOS, or you can install Nix or NixOS by following the instructions here. Something else to note is that you don't have to use nixos-anywhere, it is possible to just install NixOS manually, but is far less automated and requires more work.

Installing NixOS

Installing on a device with physical and without an installed OS

You can use netboot. Otherwise: You first want to create a bootable USB with a NixOS image on it. This is described here. But in short you want to download the ISO and copy it over to the USB device:

cp nixos.iso /dev/sdX

After booting into the USB you can now follow the instructions defined here. Note that because nixos-anywhere uses SSH, you can choose to run the nixos-anywhere command from the system with the live ISO or your own machine connected to the same local network.

Installing on device with phyiscal access but with an OS

You only need to make sure you can access the device with SSH.

Installing on a remote device

If you are setting up a device on something like Drift/OpenStack, you just need to set up an OS with SSH.

nixos-anywhere setup

You first want to create your flake and other necessary nix files for nixos-anywhere. You can follow the instructions provided here.

Creating a new host in pvv-nixos-config

First clone the repo:

git clone https://git.pvv.ntnu.no/Drift/pvv-nixos-config.git && cd pvv-nixos-config

You can now create a directory under hosts with the hostname of the device. In this directory you want to place your disko config and your hardware-config. You can generate a hardware-config with this command:

nixos-generate-config --show-hardware-config > hardware-config.nix

You then want to create a configuration.nix file. You should look at other hosts as examples for this such as Maskiner/gluttony. If you use gluttony as a starting point you should consider using systemd-boot instead if you are not on OpenStack, and removing things related to emulating other architectures. You should also make sure that the correct ethernet interface was configured. You can see which you have available by running:

ip a

The ethernet interface should start with en, such as ens3. Next you want to set values such as ip address in values.nix. The last step is to start using the config you have just created, but use the hostname you have selected:

sudo nixos-rebuild switch --update-input nixpkgs --update-input nixpkgs-unstable --no-write-lock-file --refresh --flake .#myhostname --upgrade