Get gateway, whether it's an IP or hostname

And add v6 versions
This commit is contained in:
niten 2023-11-14 08:51:36 -08:00
parent 7629a979b4
commit 326c4a1796
1 changed files with 12 additions and 2 deletions

14
lib.nix
View File

@ -37,9 +37,19 @@ let
attrNames
(filterAttrs (_: hostOpts: hostOpts.domain == domain) entities.hosts);
getSiteGateway = site: entities.sites."${site-name}".gateway-v4;
getSiteGatewayV4 = siteName:
let site = config.fudo.sites."${siteName}";
in if hasAttr "local-gateway" site then getHostIpv4 else site.gateway-v4;
getHostGateway = hostname: (getHostSite hostname).gateway-v4;
getHostGatewayV4 = hostname:
getSiteGatewayV4 config.fudo.hosts."${hostname}".site;
getSiteGatewayV6 = siteName:
let site = config.fudo.sites."${siteName}";
in if hasAttr "local-gateway" site then getHostIpv6 else site.gateway-v6;
getHostGatewayV6 = hostname:
getSiteGatewayV6 config.fudo.hosts."${hostname}".site;
in {
inherit getHostSite getHostDomain getHostRealm getHostFqdn getHostIpv4