From 9d0a0317fdcca4c70c6c4f276169f730fc9e7e22 Mon Sep 17 00:00:00 2001 From: alexion Date: Tue, 15 Sep 2026 20:25:21 -0400 Subject: [PATCH] fix(nixos): derive homepage hosts from joined registry --- configs/nixos/guests/homepage.nix | 5 ++- configs/nixos/modules/services/homepage.nix | 47 ++++++++++++--------- 2 files changed, 31 insertions(+), 21 deletions(-) diff --git a/configs/nixos/guests/homepage.nix b/configs/nixos/guests/homepage.nix index 7646765..a21048a 100644 --- a/configs/nixos/guests/homepage.nix +++ b/configs/nixos/guests/homepage.nix @@ -9,7 +9,10 @@ in { config = lib.mkIf cfg.enable { guests.homepage = { - interior.modules.services.homepage.enable = true; + interior.modules.services.homepage = { + enable = true; + hostName = config.networking.hostName; + }; limits = { memory = lib.mkDefault "1G"; diff --git a/configs/nixos/modules/services/homepage.nix b/configs/nixos/modules/services/homepage.nix index eaff1d2..b501bf5 100644 --- a/configs/nixos/modules/services/homepage.nix +++ b/configs/nixos/modules/services/homepage.nix @@ -6,7 +6,6 @@ }: let cfg = config.modules.services.homepage; - entryName = config.networking.hostName; mkRegistryPath = registryName: host: entry: "registry.${registryName}.${host}.${entry}"; @@ -23,10 +22,15 @@ let mkHref = item: if item.homepage.href != null then item.homepage.href - else if (item.composite.route or null) != null && item.composite.route.port != null then - "https://${item.composite.route.domain}" + else if (item.composite.route or null) != null then + if item.composite.route.port != null then + "https://${item.composite.route.domain}" + else if item.composite.route.http.port != null then + "http://${item.composite.route.domain}" + else + throw "${mkRegistryPath "homepage" item.host item.entry} needs href or a matching TCP route entry" else - throw "${mkRegistryPath "homepage" item.host item.entry} needs href or a matching TCP route entry"; + throw "${mkRegistryPath "homepage" item.host item.entry} needs href or a matching route entry"; mkServiceAttrs = item: lib.filterAttrs (_: value: value != null) { @@ -92,24 +96,16 @@ let homepageServices = map mkTab (lib.filter (tab: lib.hasAttr tab entriesByTab) orderedTabs); - matchingAddresses = lib.concatLists ( - lib.mapAttrsToList ( - _host: entries: - lib.optional (lib.hasAttr entryName entries) entries.${entryName} - ) registry.address - ); - - matchingDomains = lib.concatLists ( - lib.mapAttrsToList ( - _host: entries: - lib.optional (lib.hasAttr entryName entries) entries.${entryName}.domain - ) registry.route - ); + selfEntry = registry.join cfg.hostName cfg.entryName; + selfAddress = selfEntry.address or null; + selfRoute = selfEntry.route or null; derivedAllowedHosts = lib.unique ( - matchingDomains - ++ matchingAddresses - ++ map (address: "${address}:${toString cfg.listenPort}") matchingAddresses + lib.optional (selfRoute != null) selfRoute.domain + ++ lib.optionals (selfAddress != null) [ + selfAddress + "${selfAddress}:${toString cfg.listenPort}" + ] ); in { @@ -122,6 +118,17 @@ in description = "Port for Homepage to bind to."; }; + hostName = lib.mkOption { + type = lib.types.str; + description = "Host registry key that owns the Homepage guest entry."; + }; + + entryName = lib.mkOption { + type = lib.types.str; + default = "homepage"; + description = "Registry entry name for this Homepage service."; + }; + allowedHosts = lib.mkOption { type = lib.types.nullOr (lib.types.listOf lib.types.str); default = null;