Install NixOS on Hetzner Cloud: Difference between revisions

From NixOS Wiki
imported>Fadenb
m Fix channel name in nixos-infect example (missing a character)
imported>Raboof
add traditional ISO variant, dream about disko/declarative
Line 2: Line 2:


== Installation ==
== Installation ==
There are several ways to install NixOS, such as the 'traditional' ISO installation and nixos-infect.
=== traditional ISO ===
* Create a machine with any OS, such as Ubuntu
* Power it off
* Mount the available nixos 22.11-minimal ISO
* Power the machine back on
* Open the console (">_")
* Install NixOS as documented at https://nixos.org/manual/nixos/stable/index.html#sec-installation-manual (going for the "Legacy Boot (MBR)" variation)
* Power off the machine
* Unmount the iso
* Power on the machine
=== disko ===
TODO: it would be neat to document how to boot from the NixOS ISO and create the machine based on an online description including https://github.com/nix-community/disko specs - should be a quick way to set up bespoke 'throwaway' machines.


=== nixos-infect ===
=== nixos-infect ===
Line 15: Line 33:
</syntaxHighlight>
</syntaxHighlight>
* Reboot into NixOS
* Reboot into NixOS
=== Declarative ===
TODO are any of the 'declarative' configuration management systems like NixOps or Terraform able to spin up Hetzner machines according to a particular configuration? If so then it would be nice to document this here :)


== Network configuration ==
== Network configuration ==

Revision as of 08:37, 17 May 2023

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

There are several ways to install NixOS, such as the 'traditional' ISO installation and nixos-infect.

traditional ISO

  • Create a machine with any OS, such as Ubuntu
  • Power it off
  • Mount the available nixos 22.11-minimal ISO
  • Power the machine back on
  • Open the console (">_")
  • Install NixOS as documented at https://nixos.org/manual/nixos/stable/index.html#sec-installation-manual (going for the "Legacy Boot (MBR)" variation)
  • Power off the machine
  • Unmount the iso
  • Power on the machine

disko

TODO: it would be neat to document how to boot from the NixOS ISO and create the machine based on an online description including https://github.com/nix-community/disko specs - should be a quick way to set up bespoke 'throwaway' machines.

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.11 bash -x
  • Reboot into NixOS

Declarative

TODO are any of the 'declarative' configuration management systems like NixOps or Terraform able to spin up Hetzner machines according to a particular configuration? If so then it would be nice to document this here :)

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.