refactor(reverse-proxy): use route registry

This commit is contained in:
2026-08-23 23:44:22 -04:00
parent c267a2ec5c
commit b31b1c99e6
9 changed files with 311 additions and 330 deletions

View File

@@ -3,7 +3,6 @@
self,
specialArgs,
bridgeName,
reverseProxyRoutes,
}:
let
inherit (lib) escapeShellArg mapAttrsToList;
@@ -21,7 +20,7 @@ let
name,
interior ? { },
}:
{ config, lib, ... }:
{ config, lib, ... }@args:
let
optionPath = [ "guests" ] ++ lib.splitString "." name;
cfg = lib.getAttrFromPath optionPath config;
@@ -130,9 +129,19 @@ let
Left null, this guest contributes no address to the address registry.
'';
};
reverseProxy = reverseProxyRoutes.mkRouteOptions {
subject = "guest route";
enableDefault = false;
reverseProxy = {
enable = lib.mkEnableOption "a reverse-proxy route for this guest";
host = lib.mkOption {
type = lib.types.str;
description = "Primary hostname served by this guest's reverse-proxy route.";
};
port = lib.mkOption {
type = lib.types.ints.between 1 65535;
example = 3923;
description = "Backend TCP port served by this guest.";
};
};
mounts = lib.mkOption {
type = lib.types.attrsOf (
@@ -279,14 +288,10 @@ let
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 (
cfg.reverseProxy
// lib.optionalAttrs (cfg.reverseProxy.backend == null && cfg.reverseProxy.endpoint == null) {
endpoint = "${config.networking.hostName}-${machineName}";
}
)
);
registry.route.${config.networking.hostName}.${machineName} = lib.mkIf cfg.reverseProxy.enable {
domain = cfg.reverseProxy.host;
inherit (cfg.reverseProxy) port;
};
assertions = [
{
@@ -346,7 +351,7 @@ let
bindMounts = userMounts // secretMounts;
inherit specialArgs;
specialArgs = specialArgs // lib.optionalAttrs (args ? registry) { inherit (args) registry; };
config = {
imports = [