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 <masterancpp@gmail.com>
This commit is contained in:
raito 2024-10-27 21:44:54 +01:00
parent 7df7eaeb9b
commit 6441a01ab1
5 changed files with 46 additions and 2 deletions

View file

@ -1,7 +1,7 @@
{ lib, config, ... }: { lib, config, ... }:
let let
cfg = config.bagel.hardware.raito-vm; cfg = config.bagel.hardware.raito-vm;
inherit (lib) mkEnableOption mkIf mkOption types; inherit (lib) mkEnableOption mkIf mkOption types split toIntBase10;
in in
{ {
options.bagel.hardware.raito-vm = { options.bagel.hardware.raito-vm = {
@ -54,6 +54,17 @@ in
linkConfig.Name = "wan"; 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.loader.systemd-boot.enable = true;
boot.initrd.kernelModules = [ boot.initrd.kernelModules = [

View file

@ -72,6 +72,12 @@
]; ];
networking.defaultGateway6 = { interface = "uplink"; address = "2a01:584:11::1"; }; 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 = { services.coredns = {
enable = true; enable = true;
config = '' config = ''

View file

@ -135,6 +135,11 @@ in
{ address = "2a01:584:11::1:${toString cfg.num}"; prefixLength = 64; } { address = "2a01:584:11::1:${toString cfg.num}"; prefixLength = 64; }
]; ];
networking.defaultGateway6 = { interface = "uplink"; address = "2a01:584:11::1"; }; 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.targetHost = "2a01:584:11::1:${toString cfg.num}";
deployment.tags = [ "builders" ]; deployment.tags = [ "builders" ];

View file

@ -7,6 +7,7 @@
./matrix ./matrix
./monitoring ./monitoring
./uptime-kuma ./uptime-kuma
./self
./netbox ./netbox
./ofborg ./ofborg
./postgres ./postgres

21
services/self/default.nix Normal file
View file

@ -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;
};
};
};
}