From 8e07223c97bc627173e00cf8097731b9bee6a6a0 Mon Sep 17 00:00:00 2001 From: Gabriel Arazas Date: Mon, 16 Jan 2023 11:44:21 +0800 Subject: [PATCH] hosts/plover: move into systemd-networkd for network setup --- .../modules/hardware/hetzner-cloud-cx21.nix | 52 ++++++++++++++++--- hosts/plover/modules/hardware/networks.nix | 10 ++++ 2 files changed, 55 insertions(+), 7 deletions(-) create mode 100644 hosts/plover/modules/hardware/networks.nix diff --git a/hosts/plover/modules/hardware/hetzner-cloud-cx21.nix b/hosts/plover/modules/hardware/hetzner-cloud-cx21.nix index 3e7d5790..f38cd9b6 100644 --- a/hosts/plover/modules/hardware/hetzner-cloud-cx21.nix +++ b/hosts/plover/modules/hardware/hetzner-cloud-cx21.nix @@ -3,6 +3,11 @@ # Most of the filesystems listed here are supposed to be overriden to default # settings of whatever image format configuration this host system will import # from nixos-generators. +let + network = import ./networks.nix; + inherit (network) publicIP publicIPv6 privateNetworkGatewayIP; +in + { imports = [ (modulesPath + "/profiles/qemu-guest.nix") @@ -33,15 +38,48 @@ networking = { useDHCP = false; - enableIPv6 = true; + useNetworkd = true; - dhcpcd.persistent = true; + # We're using networkd to configure so we're disabling this + # service. + dhcpcd.enable = false; + }; - interfaces = { - ens3 = { - useDHCP = true; - }; - ens10.useDHCP = true; + # The interface configuration is based from the following discussion: + # https://discourse.nixos.org/t/nixos-on-hetzner-cloud-servers-ipv6/221/ + systemd.network = { + enable = true; + networks."20-wan" = { + matchConfig.Name = "ens3"; + + address = [ + # Public IPs. + publicIP + "${publicIPv6}1/64" + + # The private network IP. + "172.23.0.1/32" + + # Randomly generate from the IPv6 range. + "::" + ]; + + routes = [ + # Configuring the route with the gateway addresses for this network. + { routeConfig.Gateway = "fe80::1"; } + { routeConfig.Destination = privateNetworkGatewayIP; } + { routeConfig = { Gateway = privateNetworkGatewayIP; GatewayOnLink = true; }; } + + # Private addresses. + { routeConfig = { Destination = "172.16.0.0/12"; Type = "unreachable"; }; } + { routeConfig = { Destination = "192.168.0.0/16"; Type = "unreachable"; }; } + { routeConfig = { Destination = "10.0.0.0/8"; Type = "unreachable"; }; } + { routeConfig = { Destination = "fc00::/7"; Type = "unreachable"; }; } + ]; }; }; + + # This is to look out for any errors that will occur for my networking setup + # which is always a possibility. + systemd.services.systemd-networkd.serviceConfig.Environment = "SYSTEMD_LOG_LEVEL=debug"; } diff --git a/hosts/plover/modules/hardware/networks.nix b/hosts/plover/modules/hardware/networks.nix new file mode 100644 index 00000000..e237fe3e --- /dev/null +++ b/hosts/plover/modules/hardware/networks.nix @@ -0,0 +1,10 @@ +# It just contains a set of network-related variables mainly used for +# network-related services. Make sure to change this every time you migrate to +# a new server. +{ + publicIP = "95.217.212.19/32"; + publicIPv6 = "2a01:4f9:c011:a448::"; + + privateIPNetworkRange = "172.16.0.0/32"; + privateNetworkGatewayIP = "172.16.0.1/32"; +}