refactor(network): use address registry

This commit is contained in:
2026-08-23 23:02:43 -04:00
parent 6f963920ec
commit 70da5a7a44
5 changed files with 54 additions and 94 deletions

View File

@@ -1,42 +1,19 @@
{ lib }:
let
endpointOptions = {
address = lib.mkOption {
type = lib.types.str;
example = "10.23.20.126";
description = "Expected IP address assigned outside NixOS for this network endpoint.";
};
};
endpointFields = address: { inherit address; };
endpointType = lib.types.submodule {
options = endpointOptions;
};
endpointFields = endpoint: {
inherit (endpoint) address;
};
collectFleetEndpoints =
hosts:
collectFleetEndpoints = hosts:
lib.concatMapAttrs (
hostName: host:
let
cfg = host.config.modules.network;
hostEndpoint = lib.optionalAttrs (cfg.endpoint.address != null) {
${hostName} = endpointFields cfg.endpoint;
};
guestEndpoints = lib.mapAttrs' (
endpointName: endpoint: lib.nameValuePair "${hostName}-${endpointName}" (endpointFields endpoint)
) cfg.endpoints;
in
hostEndpoint // guestEndpoints
lib.mapAttrs' (
entryName: address:
let
endpointName = if entryName == "self" then hostName else "${hostName}-${entryName}";
in
lib.nameValuePair endpointName (endpointFields address)
) (host.config.registry.address.${hostName} or { })
) hosts;
in
{
inherit
collectFleetEndpoints
endpointFields
endpointOptions
endpointType
;
inherit collectFleetEndpoints endpointFields;
}