Keyboard meet head

Where my head meets keyboard..

NixOS on Contabo

Contabo is an EU-based VPS provider with reasonably affordable pricing. However, it does come with some compromises. The billing structure is monthly with a setup fee, making it more suitable for specific workloads. Another limitation is the limited official OS support, specifically the absence of NixOS as an option. Online resources on setting up NixOS on Contabo are scarce and can be clunky or outdated. Here's my approach that's hopefully easy to follow.

This is not necessarily the most automated way. One could use nix-infect in similar manner for example. But given the manual nature of creating Contabo VMs both on user and Contabo side, NixOS (re)installation is probably not going to be a regular occurrence worth automating. For more frequent NixOS deployment, using the paid custom images option might be more suitable. My approach here is a bit more ad-hoc.

Creating VPS🔗

There are many options available, this was tested with the cheapest VPS, so any of them should work. Just select whatever suits your needs. Here are few hints to help you a bit:

Once happy with your selection, go through the checkout, payment and wait for the confirmation email from Contabo. It should contain assigned IPv4 and IPv6 address. (not to be confused with VNC IP, that's also provided - we won't use that here, but it might be handy for recovery in the future if you mess up your network configuration)

Entering rescue system🔗

Now that our VPS is ready, log into Contabo and head over to VPS control panel. It's not the flashiest of interfaces, but we only need it to start the rescue system. To access that, click the 💾 floppy disk icon in the Rescue system column for the VPS where you want to install the NixOS. If you have multiple VPS systems, pay attention to which one are you clicking on, otherwise you might end up rebooting (or even erasing) wrong server.

On the next screen leave the Rescue System Version on the default "Debian Rescue", it already has all the utilities we need. Enter or generate root password. We will need this one briefly, so write it down, but there's no need to keep it long-term.

Click Start Rescue System, it should be booted in a couple of minutes.

kexec into the NixOS installer🔗

Once the rescue system is accessible over SSH (it will be accessible on the same IP as you got assigned for your VPS earlier) we can continue starting NixOS installer system.

First, we need to add our public key to the authorized_keys list of the root user in rescue system. The most convenient way on Linux is by using ssh-copy-id on your desktop:

ssh-copy-id root@<IP of your system here>

You will be asked to enter the root password that you written down earlier.

Afterwards you should be able to ssh as root into the rescue system without entering password. So do just that. The SSH key functionality is rather important as the script we'll be executing makes sure the same key is also allowed to log into the NixOS installer system.

The following stuff will be executed on the VPS in the rescue system shell.

First download and extract the OS:

curl -L https://github.com/nix-community/nixos-images/releases/download/nixos-23.11/nixos-kexec-installer-noninteractive-x86_64-linux.tar.gz | tar -xzf- -C /root

You should be able to choose different version of NixOS if you'd like. Here I'm using 23.11.

And now, let's kexec into it:

/root/kexec/run

This will drop your current ssh session. (It will probably hang, you can terminate it with enter, followed by ~. key sequence) Give it a few seconds to start and you should be able to log into the NixOS installer system with the same ssh -l root <system IP> you used before. There's no password set which is why it was important you set your key correctly earlier.

There's also likely to be a different server key that you'll be warned about.

If everything went well, you have essentially booted into minimal ISO image on your VPS and you can continue installation just like you're used to. 🎊

NixOS configuration🔗

I will not bother guiding you through the installation, NixOS manual can take it from here. Besides you likely have your own flake ready, don't you?

So here's just couple helpful pointers for your *.nix files:

Fin🔗

At the end of the day, NixOS is quite usable on Contabo. I just wish there were fewer hoops to jump through.

There's no comment system on this page, but I do accept feedback. If you are interested in commenting, send me a message and I may publish your comments, in edited form.