From dd30009b7e8e2e5f2278580474a5e19ecc18302e Mon Sep 17 00:00:00 2001 From: arcnmx Date: Sat, 6 Sep 2025 21:40:48 -0700 Subject: [PATCH] chore(access): network.networks.global --- ci/systems.json | 30 +++++++++++++++++++++++++++++ generate.nix | 1 + modules/system/access.nix | 6 ++++++ modules/system/network/networks.nix | 3 ++- tf/system/records/records.tf | 7 +++++-- 5 files changed, 44 insertions(+), 3 deletions(-) diff --git a/ci/systems.json b/ci/systems.json index f7227d74..72aacbf7 100644 --- a/ci/systems.json +++ b/ci/systems.json @@ -3,6 +3,7 @@ "network": { "hostName": "aya", "networks": { + "global": null, "int": { "address4": "10.9.1.73", "address6": "fd0c::49", @@ -25,6 +26,7 @@ "network": { "hostName": "chen", "networks": { + "global": null, "int": null, "local": { "address4": null, @@ -39,6 +41,7 @@ "network": { "hostName": "ct", "networks": { + "global": null, "int": null, "local": { "address4": null, @@ -53,6 +56,7 @@ "network": { "hostName": "extern-test", "networks": { + "global": null, "int": null, "local": null, "tail": null @@ -63,6 +67,7 @@ "network": { "hostName": "idp", "networks": { + "global": null, "int": { "address4": "10.9.1.170", "address6": "fd0c::aa", @@ -81,6 +86,7 @@ "network": { "hostName": "freepbx", "networks": { + "global": null, "int": null, "local": { "address4": "10.1.1.43", @@ -95,6 +101,7 @@ "network": { "hostName": "gengetsu", "networks": { + "global": null, "int": null, "local": { "address4": "10.1.1.61", @@ -109,6 +116,7 @@ "network": { "hostName": "hakurei", "networks": { + "global": null, "int": { "address4": "10.9.1.71", "address6": "fd0c::47", @@ -131,6 +139,7 @@ "network": { "hostName": "idrac-gengetsu", "networks": { + "global": null, "int": null, "local": { "address4": "10.1.1.12", @@ -145,6 +154,7 @@ "network": { "hostName": "idrac-mugetsu", "networks": { + "global": null, "int": null, "local": { "address4": "10.1.1.13", @@ -159,6 +169,7 @@ "network": { "hostName": "kasen", "networks": { + "global": null, "int": null, "local": { "address4": "10.1.1.49", @@ -177,6 +188,7 @@ "network": { "hostName": "keycloak", "networks": { + "global": null, "int": { "address4": "10.9.1.75", "address6": "fd0c::4b", @@ -195,6 +207,7 @@ "network": { "hostName": "kitchencam", "networks": { + "global": null, "int": null, "local": { "address4": null, @@ -209,6 +222,7 @@ "network": { "hostName": "koishi", "networks": { + "global": null, "int": null, "local": { "address4": "10.1.1.68", @@ -223,6 +237,7 @@ "network": { "hostName": "kuwubernetes", "networks": { + "global": null, "int": null, "local": { "address4": "10.1.1.42", @@ -237,6 +252,7 @@ "network": { "hostName": "kvm-reisen", "networks": { + "global": null, "int": null, "local": { "address4": "10.1.1.9", @@ -255,6 +271,7 @@ "network": { "hostName": "litterbox", "networks": { + "global": null, "int": { "address4": "10.9.1.74", "address6": "fd0c::4a", @@ -277,6 +294,7 @@ "network": { "hostName": "logistics", "networks": { + "global": null, "int": null, "local": { "address4": "10.1.1.63", @@ -291,6 +309,7 @@ "network": { "hostName": "mediabox", "networks": { + "global": null, "int": { "address4": "10.9.1.70", "address6": "fd0c::46", @@ -313,6 +332,7 @@ "network": { "hostName": "minecraft", "networks": { + "global": null, "int": null, "local": { "address4": "10.1.1.51", @@ -331,6 +351,7 @@ "network": { "hostName": "mugetsu", "networks": { + "global": null, "int": null, "local": { "address4": "10.1.1.60", @@ -345,6 +366,7 @@ "network": { "hostName": "nue", "networks": { + "global": null, "int": null, "local": { "address4": "10.1.1.62", @@ -363,6 +385,7 @@ "network": { "hostName": "reimu", "networks": { + "global": null, "int": { "address4": "10.9.1.72", "address6": "fd0c::48", @@ -385,6 +408,7 @@ "network": { "hostName": "reisen", "networks": { + "global": null, "int": { "address4": "10.9.1.2", "address6": "fd0c::2", @@ -403,6 +427,7 @@ "network": { "hostName": "sakuya", "networks": { + "global": null, "int": null, "local": { "address4": "10.1.1.50", @@ -421,6 +446,7 @@ "network": { "hostName": "shanghai", "networks": { + "global": null, "int": null, "local": { "address4": "10.1.1.32", @@ -439,6 +465,7 @@ "network": { "hostName": "tei", "networks": { + "global": null, "int": { "address4": "10.9.1.69", "address6": "fd0c::45", @@ -461,6 +488,7 @@ "network": { "hostName": "tewi", "networks": { + "global": null, "int": null, "local": { "address4": null, @@ -479,6 +507,7 @@ "network": { "hostName": "u7-pro", "networks": { + "global": null, "int": null, "local": { "address4": "10.1.1.3", @@ -493,6 +522,7 @@ "network": { "hostName": "utsuho", "networks": { + "global": null, "int": { "address4": "10.9.1.76", "address6": "fd0c::4c", diff --git a/generate.nix b/generate.nix index ff57c022..9b67ffed 100644 --- a/generate.nix +++ b/generate.nix @@ -75,6 +75,7 @@ int = null; local = null; tail = null; + global = null; } // mapAttrs' (_: network: nameValuePair network.name { diff --git a/modules/system/access.nix b/modules/system/access.nix index 788d1ba6..ab26a177 100644 --- a/modules/system/access.nix +++ b/modules/system/access.nix @@ -53,7 +53,10 @@ fallback = if nameAllowed then lib.warn "getAddressFor hostname fallback for ${config.networking.hostName} -> ${hostName}@${network}" (access.getHostnameFor hostName network) + else if forSystem.access.global.enable + then lib.warn "getAddressFor global fallback for ${config.networking.hostName} -> ${hostName}@${network}" (mkGetAddressFor true addressForAttr hostName "global") else err; + global = forSystem.access.${addressForAttr}.global or forSystem.access.address4ForNetwork.global or fallback; local = forSystem.access.${addressForAttr}.local or forSystem.access.address4ForNetwork.local or fallback; int = forSystem.access.${addressForAttr}.int or forSystem.access.address4ForNetwork.int or fallback; tail = forSystem.access.${addressForAttr}.tail or fallback; @@ -66,6 +69,8 @@ then int else if has'Local && forSystemHas "local" then local + else if forSystem.access.global.enable && forSystemHas "global" + then global else fallback; ${ if has'Local @@ -85,6 +90,7 @@ else null } = tail; + global = global; } .${network} or fallback; diff --git a/modules/system/network/networks.nix b/modules/system/network/networks.nix index 690ea778..7bd5be12 100644 --- a/modules/system/network/networks.nix +++ b/modules/system/network/networks.nix @@ -20,6 +20,7 @@ prefix = "fd0a:"; }; int.slaac.prefix = "fd0c:"; + global.domain = systemConfig.access.domain; }; in { options = with lib.types; { @@ -68,7 +69,7 @@ ); postfix = mkIf (config.macAddress != null) (mkOptionDefault (eui64 config.macAddress)); }; - domain = mkOptionDefault "${config.name}.${systemConfig.access.domain}"; + domain = mkOptionDefault knownNetworks.${config.name}.domain or "${config.name}.${systemConfig.access.domain}"; fqdn = mkOptionDefault (mapNullable (domain: "${systemConfig.access.hostName}.${domain}") config.domain); address6 = mkIf config.slaac.enable (mkOptionDefault "${config.slaac.prefix}:${config.slaac.postfix}"); }; diff --git a/tf/system/records/records.tf b/tf/system/records/records.tf index 861402bd..97827d45 100644 --- a/tf/system/records/records.tf +++ b/tf/system/records/records.tf @@ -98,6 +98,9 @@ locals { tailscale_v4 = coalesce(var.tailscale_v4, local.tailscale_net.address4, local.empty_address) tailscale_v6 = coalesce(var.tailscale_v6, local.tailscale_net.address6, local.empty_address) global_name = coalesce(var.global_name, local.name) + global_net = coalesce(var.net_data.networks.global, local.empty_net) + global_v4 = coalesce(var.global_v4, local.global_net.address4, local.empty_address) + global_v6 = coalesce(var.global_v6, local.global_net.address6, local.empty_address) has_tailscale = local.tailscale_v4 != local.empty_address || local.tailscale_v6 != local.empty_address has_int = local.int_v4 != local.empty_address || local.int_v6 != local.empty_address @@ -114,7 +117,7 @@ locals { }, { name = local.global_name, - value = var.global_v4, + value = local.global_v4, }, { name = local.int_name, @@ -133,7 +136,7 @@ locals { }, { name = local.global_name, - value = var.global_v6, + value = local.global_v6, }, { name = local.int_name,