From 5324b48cc3d9178e1f6865e5b04a18494480979b Mon Sep 17 00:00:00 2001 From: Lin Yinfeng Date: Fri, 28 Jul 2023 22:31:01 +0800 Subject: [PATCH] networking/dn42: fix peering, bird-lg, and dn42-site --- nixos/modules/networking/dn42/default.nix | 6 ++++++ nixos/profiles/networking/dn42/default.nix | 2 ++ nixos/profiles/services/bird-lg/default.nix | 7 +++---- nixos/profiles/services/dn42-site/default.nix | 11 +++++++---- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/nixos/modules/networking/dn42/default.nix b/nixos/modules/networking/dn42/default.nix index 8dd22dce7..b6d9d8cfc 100644 --- a/nixos/modules/networking/dn42/default.nix +++ b/nixos/modules/networking/dn42/default.nix @@ -40,6 +40,12 @@ type = lib.types.str; default = name; }; + addressesV4 = lib.mkOption { + type = with lib.types; listOf str; + }; + addressesV6 = lib.mkOption { + type = with lib.types; listOf str; + }; preferredAddressV4 = lib.mkOption { type = lib.types.str; }; diff --git a/nixos/profiles/networking/dn42/default.nix b/nixos/profiles/networking/dn42/default.nix index be3130532..a5594746b 100644 --- a/nixos/profiles/networking/dn42/default.nix +++ b/nixos/profiles/networking/dn42/default.nix @@ -31,6 +31,8 @@ }; }; mkHostDn42Cfg = name: hostData: { + addressesV4 = hostData.dn42_addresses_v4; + addressesV6 = hostData.dn42_addresses_v6; preferredAddressV4 = lib.elemAt hostData.dn42_addresses_v4 0; preferredAddressV6 = lib.elemAt hostData.dn42_addresses_v6 0; }; diff --git a/nixos/profiles/services/bird-lg/default.nix b/nixos/profiles/services/bird-lg/default.nix index 5618e1d8e..bb3c5a95f 100644 --- a/nixos/profiles/services/bird-lg/default.nix +++ b/nixos/profiles/services/bird-lg/default.nix @@ -4,7 +4,8 @@ ... }: let # only show servers with endpoints - hostFilter = _name: hostCfg: (hostCfg.endpointsV4 ++ hostCfg.endpointsV6) != []; + inherit (config.lib.self) data; + hostFilter = name: (data.hosts.${name}.endpoints_v4 ++ data.hosts.${name}.endpoints_v6) != []; in { services.bird-lg.frontend = { enable = true; @@ -13,9 +14,7 @@ in { domain = "ts.li7g.com"; proxyPort = config.ports.bird-lg-proxy; whois = "whois.dn42"; - servers = - lib.mapAttrsToList (_: hostCfg: hostCfg.name) - (lib.filterAttrs hostFilter config.networking.dn42.autonomousSystem.mesh.hosts); + servers = lib.filter hostFilter (lib.attrNames config.networking.dn42.autonomousSystem.hosts); protocolFilter = []; titleBrand = "li7g.com"; navbar.allServers = "ALL"; diff --git a/nixos/profiles/services/dn42-site/default.nix b/nixos/profiles/services/dn42-site/default.nix index 03ceb2b90..63155ab50 100644 --- a/nixos/profiles/services/dn42-site/default.nix +++ b/nixos/profiles/services/dn42-site/default.nix @@ -40,7 +40,10 @@ asCfg = cfg.autonomousSystem; json = pkgs.formats.json {}; data = config.lib.self.data; - filterHost = name: hostCfg: (hostCfg.endpointsV4 ++ hostCfg.endpointsV6) != []; + filterHost = name: _hostCfg: + (data.hosts.${name}.endpoints_v4 + ++ data.hosts.${name}.endpoints_v6) + != []; mkHostInfo = name: hostCfg: lib.recursiveUpdate { dn42 = { @@ -60,8 +63,8 @@ traffic_control = config.passthru.dn42TrafficControlTable.${name}.enable; wireguard = { endpoints = { - v4 = hostCfg.endpointsV4; - v6 = hostCfg.endpointsV6; + v4 = data.hosts.${name}.endpoints_v4; + v6 = data.hosts.${name}.endpoints_v6; }; public_key = data.hosts.${name}.wireguard_public_key; port = "Last 5 digits of your ASN"; @@ -77,7 +80,7 @@ v6 = asCfg.cidrV6; }; }; - hosts = lib.mapAttrs mkHostInfo (lib.filterAttrs filterHost asCfg.mesh.hosts); + hosts = lib.mapAttrs mkHostInfo (lib.filterAttrs filterHost asCfg.hosts); }; siteRoot = pkgs.runCommandNoCC "dn42-site-root" {} '' mkdir -p $out