Install NixOS on Hetzner Online
This article is about installing NixOS on Hetzner Online, which provides dedicated bare-metal servers. This is not to be confused by Hetzner cloud, that provides VMs. There are three ways at the time to install NixOS on Hetzner
- From Hetzner's rescue image one can boot into the nixos installer using a custom kexec image that is configured with the fixed IPv6 provided by Hetzner and also contain your ssh key. Tip: The kexec tarball as generated by nixos-generators can remain put into the /boot partition for future use.
- Hetzner also provides an interface to upload your own ISO-images. Also here you may want to build your own iso-image, which has openssh with ssh keys due the lack of a remote console.
- An easier method to install NixOS on Hetzner, is to use the existing integration into NixOps.
Network configuration
From Hetzner's web interface, one can obtain both ipv4/ipv6 addresses and gateways. Hetzner does announce ipv6 addresses servers, so you need to assign those statically. In this example we use networkd to configure the interface. The same configuration can be used for both the kexec installation image and the final server configuration.
{ ... }: {
# this make sure that our interface is named `eth0`,
# this should be ok as long as you don't have multiple physical network cards
networking.usePredictableInterfaceNames = false;
systemd.network = {
enable = true;
networks."eth0".extraConfig = ''
[Match]
Name = eth0
[Network]
# Add your own assigned ipv6 subnet here here!
Address = 2a01:4f9:ffff::1/64
Gateway = fe80::1
'';
};
}
Another possibility is to use networking.interfaces
:
let
external-mac = "00:11:22:33:44:55";
ext-if = "et0";
external-ip = "144.x.x.x";
external-ip6 = "2a01:XXXX:XXXX::1";
external-gw6 = "fe80::1";
external-netmask = 27;
external-netmask6 = 64;
in {
# rename the external interface based on the MAC of the interface
services.udev.extraRules = ''SUBSYSTEM=="net", ATTR{address}=="${external-mac}", NAME="${ext-if}"'';
networking = {
interfaces."${ext-if}" = {
ipv4.addresses = [{
address = external-ip;
prefixLength = external-netmask;
}];
ipv6.addresses = [{
address = external-ip6;
prefixLength = external-netmask6;
}];
};
defaultGateway6 = external-gw6;
defaultGateway = external-gw;
};
}