From 6f963920ec1abed62b36ed4b0f4ae680938c4e76 Mon Sep 17 00:00:00 2001 From: alexion Date: Sun, 23 Aug 2026 19:55:23 -0400 Subject: [PATCH] feat(registry): add generic fleet namespace --- flake.nix | 45 ++++++++++++++++++++++++++++++++++++++++++++ lib/default.nix | 4 ++++ lib/registry.nix | 45 ++++++++++++++++++++++++++++++++++++++++++++ registry/address.nix | 4 ++++ 4 files changed, 98 insertions(+) create mode 100644 lib/registry.nix create mode 100644 registry/address.nix diff --git a/flake.nix b/flake.nix index 03460e4..cc2bccf 100644 --- a/flake.nix +++ b/flake.nix @@ -246,6 +246,51 @@ touch $out ''; + generic-registry-fleet-view = + let + hosts = { + alpha = lib.nixosSystem { + system = "x86_64-linux"; + specialArgs.registry = registry; + modules = [ + self.lib.registry.module + { + registry.address.alpha.service = "10.0.0.5"; + system.stateVersion = "26.11"; + } + ]; + }; + beta = lib.nixosSystem { + system = "x86_64-linux"; + specialArgs.registry = registry; + modules = [ + self.lib.registry.module + ( + { registry, ... }: + { + environment.etc."registry-address-check".text = registry.address.alpha.service; + system.stateVersion = "26.11"; + } + ) + ]; + }; + }; + registry = self.lib.registry.collect { inherit hosts; }; + betaConfig = hosts.beta.config; + in + pkgs.runCommand "generic-registry-fleet-view-check" { } '' + ${ + lib.optionalString ( + !( + registry.address.alpha.service == "10.0.0.5" + && betaConfig.environment.etc."registry-address-check".text == "10.0.0.5" + && !(registry.address ? alpha-service) + ) + ) "exit 1" + } + touch $out + ''; + network-endpoint-fleet-registry = let hostEndpointConfig = diff --git a/lib/default.nix b/lib/default.nix index b577a64..ba3a9f5 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -14,6 +14,7 @@ let ; serviceIdentityRegistry = import ./service-identities.nix { inherit lib; }; + registry = import ./registry.nix { inherit lib self; }; networkEndpoints = import ./network-endpoints.nix { inherit lib; }; reverseProxyRoutes = import ./reverse-proxy-routes.nix { inherit lib; }; @@ -41,6 +42,7 @@ let { inherit inputs networkFleetEndpoints self; my = self.lib; + registry = self.lib.registry.collect { hosts = self.nixosConfigurations; }; reverseProxyFleetRoutes = self.lib.reverseProxyRoutes.collectFleetRoutes self.nixosConfigurations networkFleetEndpoints; }; @@ -71,6 +73,7 @@ let inputs.disko.nixosModules.disko inputs.sops-nix.nixosModules.sops inputs.stylix.nixosModules.stylix + registry.module (self + "/system.nix") (self + "/hosts/${hostName}") { networking.hostName = hostName; } @@ -90,6 +93,7 @@ in mkHost mkHosts bridgeName + registry networkEndpoints reverseProxyRoutes ; diff --git a/lib/registry.nix b/lib/registry.nix new file mode 100644 index 0000000..d43d6f4 --- /dev/null +++ b/lib/registry.nix @@ -0,0 +1,45 @@ +{ lib, self }: +let + inherit (lib) + filterAttrs + hasSuffix + mapAttrs + mapAttrs' + mkOption + nameValuePair + removeSuffix + types + ; + + registryName = fileName: removeSuffix ".nix" fileName; + + registryOption = registry: mkOption { + type = types.attrsOf (types.attrsOf registry.type); + default = { }; + description = '' + Lazily collected fleet-visible registry entries, nested by host and entry name. + ''; + }; + + definitions = mapAttrs' ( + name: type: + let + path = self + "/registry/${name}"; + in + nameValuePair (registryName name) (import path { inherit lib; }) + ) (filterAttrs (name: type: type == "regular" && hasSuffix ".nix" name) (builtins.readDir (self + "/registry"))); +in +{ + inherit definitions; + + module = { + options.registry = mapAttrs (_name: registry: registryOption registry) definitions; + }; + + collect = + { hosts }: + mapAttrs ( + registryName: _registry: + mapAttrs (hostName: host: host.config.registry.${registryName}.${hostName} or { }) hosts + ) definitions; +} diff --git a/registry/address.nix b/registry/address.nix new file mode 100644 index 0000000..dab4003 --- /dev/null +++ b/registry/address.nix @@ -0,0 +1,4 @@ +{ lib }: +{ + type = lib.types.str; +}