From 6441a01ab1bb39208411db7e77e8d8c4afd89e74 Mon Sep 17 00:00:00 2001 From: Raito Bezarius Date: Sun, 27 Oct 2024 21:44:54 +0100 Subject: [PATCH] feat: introduce awareness module for WAN addresses Introduce a data-only module to perform abstraction on the deployment, we use it for WAN for now. The usecase is service discovery for simple cases. Signed-off-by: Raito Bezarius --- common/hardware/raito-vm.nix | 15 +++++++++++++-- hosts/build-coord/hardware.nix | 6 ++++++ services/baremetal-builder/default.nix | 5 +++++ services/default.nix | 1 + services/self/default.nix | 21 +++++++++++++++++++++ 5 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 services/self/default.nix diff --git a/common/hardware/raito-vm.nix b/common/hardware/raito-vm.nix index d17373d..0ae4e64 100644 --- a/common/hardware/raito-vm.nix +++ b/common/hardware/raito-vm.nix @@ -1,7 +1,7 @@ -{ lib, config, ... }: +{ lib, config, ... }: let cfg = config.bagel.hardware.raito-vm; - inherit (lib) mkEnableOption mkIf mkOption types; + inherit (lib) mkEnableOption mkIf mkOption types split toIntBase10; in { options.bagel.hardware.raito-vm = { @@ -54,6 +54,17 @@ in linkConfig.Name = "wan"; }; + bagel.infra.self.wan = + let + parts = split "/" cfg.networking.wan.address; + address = builtins.elemAt parts 0; + prefixLength = toIntBase10 (builtins.elemAt 1 parts); + in + { + family = "inet6"; + inherit address prefixLength; + }; + boot.loader.systemd-boot.enable = true; boot.initrd.kernelModules = [ diff --git a/hosts/build-coord/hardware.nix b/hosts/build-coord/hardware.nix index f9a9a8c..112bc7c 100644 --- a/hosts/build-coord/hardware.nix +++ b/hosts/build-coord/hardware.nix @@ -72,6 +72,12 @@ ]; networking.defaultGateway6 = { interface = "uplink"; address = "2a01:584:11::1"; }; + bagel.infra.self.wan = { + family = "inet6"; + address = "2a01:584:11::1:11"; + prefixLength = 64; + }; + services.coredns = { enable = true; config = '' diff --git a/services/baremetal-builder/default.nix b/services/baremetal-builder/default.nix index fd9075a..f79d3fc 100644 --- a/services/baremetal-builder/default.nix +++ b/services/baremetal-builder/default.nix @@ -135,6 +135,11 @@ in { address = "2a01:584:11::1:${toString cfg.num}"; prefixLength = 64; } ]; networking.defaultGateway6 = { interface = "uplink"; address = "2a01:584:11::1"; }; + bagel.infra.self.wan = { + family = "inet6"; + address = "2a01:584:11::1:${toString cfg.num}"; + prefixLength = 64; + }; deployment.targetHost = "2a01:584:11::1:${toString cfg.num}"; deployment.tags = [ "builders" ]; diff --git a/services/default.nix b/services/default.nix index 08a2272..d0971ec 100644 --- a/services/default.nix +++ b/services/default.nix @@ -7,6 +7,7 @@ ./matrix ./monitoring ./uptime-kuma + ./self ./netbox ./ofborg ./postgres diff --git a/services/self/default.nix b/services/self/default.nix new file mode 100644 index 0000000..c761c99 --- /dev/null +++ b/services/self/default.nix @@ -0,0 +1,21 @@ +# This is a data-only module for other modules consumption. +{ lib, ... }: +let + inherit (lib) mkOption types; +in +{ + options.bagel.infra.self = { + wan = { + family = mkOption { + type = types.enum [ "inet" "inet6" ]; + default = "inet6"; + }; + address = mkOption { + type = types.str; + }; + prefixLength = mkOption { + type = types.int; + }; + }; + }; +}