Skip to content

Commit

Permalink
networking/dn42: fix peering, bird-lg, and dn42-site
Browse files Browse the repository at this point in the history
  • Loading branch information
linyinfeng committed Jul 28, 2023
1 parent 9a674a1 commit 5324b48
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
6 changes: 6 additions & 0 deletions nixos/modules/networking/dn42/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
2 changes: 2 additions & 0 deletions nixos/profiles/networking/dn42/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
7 changes: 3 additions & 4 deletions nixos/profiles/services/bird-lg/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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";
Expand Down
11 changes: 7 additions & 4 deletions nixos/profiles/services/dn42-site/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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";
Expand All @@ -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
Expand Down

0 comments on commit 5324b48

Please sign in to comment.