Install NixOS on Hetzner Cloud

From NixOS Wiki
Revision as of 19:27, 25 April 2023 by imported>Riotbib
Note: This article is about installing NixOS on Hetzner Cloud, which provides VPS cloud servers. It is not to be confused with Hetzner Online, which provides dedicated bare-metal servers.

Installation

nixos-infect

Beside the manual installation, one way to setup NixOS is to replace an existing installation, for example the latest Ubuntu image, with nixos-infect. The installation process follows these steps:

  • Boot into the existing operating system, preferably Ubuntu or Debian
  • Login as root or with root permissions
  • Deploy your SSH public key for the current root user. This key will be used later for authentication into the NixOS system.
  • Run following script. Replace NIX_CHANNEL variable with the version string you wish to install.
curl https://raw.githubusercontent.com/elitak/nixos-infect/master/nixos-infect | NIX_CHANNEL=nixos-22.1 bash -x
  • Reboot into NixOS

Network configuration

The public IPv4 address of the server will be automatically obtained by NixOS via DHCP, no extra configuration needed. For IPv6 you have to assign the network address and gateway manually like this:

networking = {
  interfaces.ens3.ipv6.addresses = [{
    address = "2a01:4f8:....:....::";
    prefixLength = 64;
  }];
  defaultGateway6 = {
    address = "fe80::1";
    interface = "ens3";
  };
};

Replace the address part with the correct IPv6 address of your instance. You can find it on the Hetzner Cloud Console by selecting the respective server and navigation to the "Networking" section in the left menu.