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 {
guests.homepage = {
interior.modules.services.homepage.enable = true;
interior.modules.services.homepage = {
enable = true;
hostName = config.networking.hostName;
};
limits = {
memory = lib.mkDefault "1G";

View File

@@ -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;