Files
nixos-installer/modules/hardware/hetzner-vps.nix.md
Niklas Gollenstede dd8fc696f4 improve installation scripting:
further improve scripting robustness, add fs.disks.devices.partitionDuringInstallation, ad fs.zfs.datasets.*.recursiveProps, add deploy-system-to-hetzner-vps install script
2023-05-02 02:13:24 +02:00

2.2 KiB

/*

Hetzner Cloud VPS Base Config

This is "device" type specific configuration for Hetzner's cloud VPS VMs.

Installation / Testing

Since the VPSes are qemu VMs, the systems can quite accurately be tested locally in qemu:

 nix run '.#<hostname>' -- run-qemu --install

Once the system works locally, a fresh installation can be deployed to a new VPS:

 HCLOUD_TOKEN=... nix run '.#<hostname>' -- deploy-system-to-hetzner-vps '<server-name>' '<server-type>'

Or deploy an existing image using deploy-image-to-hetzner-vps. The HCLOUD_TOKEN needs to be created in the cloud console, is specific to the cloud project, has to have write access, and can be revoked after the installation.

Alternatively, manually create a new server instance, boot it into rescue mode, and copy the installed image to it:

cat $image | zstd | ssh $newServerIP 'zstdcat >/dev/sda && sync'

If the system image is very large, even if it is mostly empty and with compression, the copy process can take quite a while. Declaring a smaller image size and expanding it on boot may be a workaround, but (since it depends on the disk partitioning and filesystems used) is out of scope here.

Implementation

#*/# end of MarkDown, beginning of NixOS module:
dirname: inputs: args@{ config, pkgs, lib, ... }: let inherit (inputs.self) lib; in let
    prefix = inputs.config.prefix;
    cfg = config.${prefix}.hardware.hetzner-vps;
in {

    options.${prefix} = { hardware.hetzner-vps = {
        enable = lib.mkEnableOption "the core hardware configuration for Hetzner VPS (virtual) hardware";
    }; };

    config = lib.mkIf cfg.enable ({

        ${prefix} ={
            bootloader.extlinux.enable = true;
            setup.scripts.hetzner-deploy.path = ./hetzner-deploy-vps.sh;
        };

        networking.interfaces.eth0.useDHCP = true;
        networking.interfaces.eth0.ipv6.routes = [ { address = "::"; prefixLength = 0; via = "fe80::1"; } ];
        networking.timeServers = [ "ntp1.hetzner.de" "ntp2.hetzner.com" "ntp3.hetzner.net" ]; # (these should be most accurate)

        profiles.qemu-guest.enable = true;

    });
}