fix(nixos): derive homepage hosts from joined registry

This commit is contained in:
2026-09-15 20:25:21 -04:00
parent a002f5348b
commit 9d0a0317fd
2 changed files with 31 additions and 21 deletions

View File

@@ -9,7 +9,10 @@ in
{ {
config = lib.mkIf cfg.enable { config = lib.mkIf cfg.enable {
guests.homepage = { guests.homepage = {
interior.modules.services.homepage.enable = true; interior.modules.services.homepage = {
enable = true;
hostName = config.networking.hostName;
};
limits = { limits = {
memory = lib.mkDefault "1G"; memory = lib.mkDefault "1G";

View File

@@ -6,7 +6,6 @@
}: }:
let let
cfg = config.modules.services.homepage; cfg = config.modules.services.homepage;
entryName = config.networking.hostName;
mkRegistryPath = registryName: host: entry: "registry.${registryName}.${host}.${entry}"; mkRegistryPath = registryName: host: entry: "registry.${registryName}.${host}.${entry}";
@@ -23,10 +22,15 @@ let
mkHref = item: mkHref = item:
if item.homepage.href != null then if item.homepage.href != null then
item.homepage.href item.homepage.href
else if (item.composite.route or null) != null && item.composite.route.port != null then else if (item.composite.route or null) != null then
"https://${item.composite.route.domain}" 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 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: mkServiceAttrs = item:
lib.filterAttrs (_: value: value != null) { lib.filterAttrs (_: value: value != null) {
@@ -92,24 +96,16 @@ let
homepageServices = map mkTab (lib.filter (tab: lib.hasAttr tab entriesByTab) orderedTabs); homepageServices = map mkTab (lib.filter (tab: lib.hasAttr tab entriesByTab) orderedTabs);
matchingAddresses = lib.concatLists ( selfEntry = registry.join cfg.hostName cfg.entryName;
lib.mapAttrsToList ( selfAddress = selfEntry.address or null;
_host: entries: selfRoute = selfEntry.route or null;
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
);
derivedAllowedHosts = lib.unique ( derivedAllowedHosts = lib.unique (
matchingDomains lib.optional (selfRoute != null) selfRoute.domain
++ matchingAddresses ++ lib.optionals (selfAddress != null) [
++ map (address: "${address}:${toString cfg.listenPort}") matchingAddresses selfAddress
"${selfAddress}:${toString cfg.listenPort}"
]
); );
in in
{ {
@@ -122,6 +118,17 @@ in
description = "Port for Homepage to bind to."; 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 { allowedHosts = lib.mkOption {
type = lib.types.nullOr (lib.types.listOf lib.types.str); type = lib.types.nullOr (lib.types.listOf lib.types.str);
default = null; default = null;