From 1397576538e3c4f30caaeca85e333d4ae9adf402 Mon Sep 17 00:00:00 2001 From: alexion Date: Thu, 15 Oct 2026 13:57:45 -0400 Subject: [PATCH] refactor(reverse-proxy): simplify virtual host generation --- configs/nixos/AGENTS.md | 2 + .../nixos/modules/services/reverse-proxy.nix | 50 ++----------------- 2 files changed, 7 insertions(+), 45 deletions(-) diff --git a/configs/nixos/AGENTS.md b/configs/nixos/AGENTS.md index 867195c..50fe4fd 100644 --- a/configs/nixos/AGENTS.md +++ b/configs/nixos/AGENTS.md @@ -65,3 +65,5 @@ and Zeus), not in the generic host module. - Module-relative paths resolve from the module file. Update them when moving a module into a subdirectory. - On Pikachu, `uptime` does not support `-s`. Use `who -b` to report the boot time. +- Evaluating a NixOS guest's inner `config.services.nginx` can force incomplete ACME values. + Evaluate the parent host's `config.system.build.toplevel` to validate an ACME-enabled guest. diff --git a/configs/nixos/modules/services/reverse-proxy.nix b/configs/nixos/modules/services/reverse-proxy.nix index a9b7e3e..530c76b 100644 --- a/configs/nixos/modules/services/reverse-proxy.nix +++ b/configs/nixos/modules/services/reverse-proxy.nix @@ -40,43 +40,14 @@ let proxy_pass ${stream.address}:${toString stream.port}; } '') generatedUdpStreams; - generatedVirtualHosts = - if duplicateDomainMessages != [ ] then - throw (builtins.head duplicateDomainMessages) - else - lib.listToAttrs generatedVirtualHostList; + generatedVirtualHosts = lib.listToAttrs generatedVirtualHostList; - duplicateDomainMessages = lib.concatLists ( - lib.mapAttrsToList ( - domain: virtualHosts: - if lib.length virtualHosts > 1 then - [ - "duplicate route domain ${domain} in ${ - lib.concatMapStringsSep " and " ( - virtualHost: mkRegistryPath virtualHost.registryName virtualHost.host virtualHost.entry - ) virtualHosts - }" - ] - else - [ ] - ) virtualHostsByDomain - ); - - virtualHostsByDomain = lib.foldl' ( - acc: virtualHost: - acc - // { - ${virtualHost.name} = (acc.${virtualHost.name} or [ ]) ++ [ virtualHost ]; - } - ) { } generatedVirtualHostList; - - generatedVirtualHostList = generatedHttpsVirtualHostList ++ generatedHttpVirtualHostList; - - generatedHttpsVirtualHostList = lib.concatLists ( + # Route registry validation already requires unique domains. + generatedVirtualHostList = lib.concatLists ( lib.mapAttrsToList ( host: routes: - lib.mapAttrsToList (entry: _route: mkVirtualHost host entry "https") ( - lib.filterAttrs (_entry: route: route.protocol == "https") routes + lib.mapAttrsToList (entry: route: mkVirtualHost host entry route.protocol) ( + lib.filterAttrs (_entry: route: route.protocol != "udp") routes ) ) registry.route ); @@ -93,8 +64,6 @@ let inherit (route) port; in { - inherit host entry; - registryName = "route"; name = route.domain; value = { forceSSL = !isHttp; @@ -108,15 +77,6 @@ let mkBackend = address: port: "http://${address}:${toString port}"; - generatedHttpVirtualHostList = lib.concatLists ( - lib.mapAttrsToList ( - host: routes: - lib.mapAttrsToList (entry: _route: mkVirtualHost host entry "http") ( - lib.filterAttrs (_entry: route: route.protocol == "http") routes - ) - ) registry.route - ); - mkRegistryPath = registryName: host: entry: "registry.${registryName}.${host}.${entry}"; -- 2.47.3