refactor(network): use address registry
This commit was merged in pull request #60.
This commit is contained in:
@@ -78,8 +78,7 @@ let
|
||||
systemd.network.networks."20-eth0" = {
|
||||
matchConfig.Name = "eth0";
|
||||
linkConfig.MACAddress = cfg.mac;
|
||||
networkConfig = lib.mkIf (cfg.address == null) { DHCP = "yes"; };
|
||||
address = lib.mkIf (cfg.address != null) [ cfg.address ];
|
||||
networkConfig.DHCP = "yes";
|
||||
};
|
||||
};
|
||||
};
|
||||
@@ -125,24 +124,12 @@ let
|
||||
address = lib.mkOption {
|
||||
type = lib.types.nullOr lib.types.str;
|
||||
default = null;
|
||||
example = "10.0.10.5/24";
|
||||
example = "10.23.20.126";
|
||||
description = ''
|
||||
The guest's static address, in CIDR form, on its VLAN. Left null, the
|
||||
guest takes its address by DHCP, keeping IP management at the router.
|
||||
Expected IP address assigned outside NixOS for this guest.
|
||||
Left null, this guest contributes no address to the address registry.
|
||||
'';
|
||||
};
|
||||
endpoint = {
|
||||
address = lib.mkOption {
|
||||
type = lib.types.nullOr lib.types.str;
|
||||
default = null;
|
||||
example = "10.23.20.126";
|
||||
description = ''
|
||||
Expected IP address assigned outside NixOS for this guest's
|
||||
network endpoint. Left null, this guest contributes no endpoint to
|
||||
the fleet endpoint registry.
|
||||
'';
|
||||
};
|
||||
};
|
||||
reverseProxy = reverseProxyRoutes.mkRouteOptions {
|
||||
subject = "guest route";
|
||||
enableDefault = false;
|
||||
@@ -290,9 +277,7 @@ let
|
||||
config = lib.mkIf cfg.enable {
|
||||
sops.secrets = lib.genAttrs cfg.secrets (_: { });
|
||||
|
||||
modules.network.endpoints.${machineName} = lib.mkIf (cfg.endpoint.address != null) {
|
||||
inherit (cfg.endpoint) address;
|
||||
};
|
||||
registry.address.${config.networking.hostName}.${machineName} = lib.mkIf (cfg.address != null) cfg.address;
|
||||
|
||||
modules.reverse-proxy.routes.${machineName} = lib.mkIf cfg.reverseProxy.enable (
|
||||
reverseProxyRoutes.routeFields (
|
||||
|
||||
@@ -1,42 +1,20 @@
|
||||
{ lib }:
|
||||
# TODO: Remove this compatibility bridge when route backend resolution reads registry.address directly.
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user