So I had this Idea to install NixOS in the Hetzner Cloud (not to be confused with Hetzner Online for which a page in the NixOS wiki does exist). Searching a bit, I didn't find any instruction or experience report on the topic, so this is me formulating my experience.

The goal

The goal of all of this is to have a NixOS instance running on one of the Hetzner Cloud servers /CP?X[1-5]1/.The web consoles has a rather obvious option to rebuild the server, but this only includes some distors and not the NixOS we want to install.

The way to go

There is another option in the cloud console: "ISO IMAGES":

Mounting an ISO Image will attach it to the virtual drive in your server.
Rebooting your server while a ISO image is mounted will cause it to boot from the image. After rebooting the server you can access our web console to complete the installation. Some images may require you to press a key in the console during boot, otherwise the server will boot from disk again.

This allows selecting one of the given Available images in order to mount it.
The list is pretty long, but using the search functionality, we can search for NixOS.

Two images pop up:

NixOS 20.03 (amd64/graphical) nixos-plasma5-20.03.1422.1e90c46c2d9-x86_64-linux
NixOS 20.03 (amd64/minimal) nixos-minimal-20.03.1596.2faa76db27c-x86_64-linux.iso

The graphical version allows to use the default KDE setup to be used when booting from that iso, the minimal one doesn't supply a Desktop Environment by default.

If you do now want to install nixos on one of the hetzner servers, mount the minimal one, as you'll only be able to use the cloud console at first and you'll (probably) be only using the console resulting in not needing a graphical interface.

After having mounted the ISO, proceed to restart the server using the POWER → POWER CYCLE option provided in the web interface. Then open a cloud console (the little console icon in the top right corner).

Installing NixOS

Installing NixOS ist fairly straitfoward (assuming you just want to get NixOS running). The Installation Guide does a great job at explaining how to install nixos, here the steps I took for installing:

  • Booting the system worked on it's own, as the hetzner server boots from the iso image inserted by default
  • Networking did work out of the box, nothing to do here
  • Partitioning is done following the steps described in 2.2.2 (Legacy Boot (MBR)). I chose to create a 2GiB big swap partition as the space availible in the CX11 i used to test this is fairly limited
  • Formatting results in nothing special, but it should be noted that I didn't create any LVM volumes or crypted the disks.
  • Installing did simply work without ANY problem.

The after the installation was done, I proceeded to unmount the mounted ISO in the web-interface and reboot the machine using the POWER CYCLE feature as used before.

After reboot

After rebooting, nothing is installed yet (except vim and wget, but apart from that there is nothing). Thus, no ssh server is running that can be used to connect to the server. This is one of the first thing I'd suggest activating: edit the /etc/nixos/configuration.nix file uncommenting the services.openssh.enable = true; option. Then save the file and rebuild nixos using nixos-rebuild switch (as root).

This results in nixos exposing the ssh server. In order to connect, insert your public-key into the ~/.ssh/authorized_keys file (you might want to host it somewhere (<username>.keys contains your public-key (if you've uploaded one)) and pull it from there, as you can't paste into the cloud console (atleast I don't know how)).

# curl<username>.keys > /root/.ssh/authorized_keys


Well, it does work, I'll probably write a blogpost on how this all turns out after using it for a bit in a while.