fix(nixos): derive homepage allowed hosts

This commit is contained in:
2026-09-15 20:16:16 -04:00
parent 2d50571fa2
commit a002f5348b
3 changed files with 26 additions and 21 deletions

View File

@@ -7,20 +7,9 @@ let
cfg = config.guests.homepage; cfg = config.guests.homepage;
in in
{ {
options.guests.homepage = {
allowedHosts = lib.mkOption {
type = lib.types.listOf lib.types.str;
default = [ "home" ];
description = "Host headers accepted by Homepage.";
};
};
config = lib.mkIf cfg.enable { config = lib.mkIf cfg.enable {
guests.homepage = { guests.homepage = {
interior.modules.services.homepage = { interior.modules.services.homepage.enable = true;
enable = true;
inherit (cfg) allowedHosts;
};
limits = { limits = {
memory = lib.mkDefault "1G"; memory = lib.mkDefault "1G";

View File

@@ -148,11 +148,6 @@
enable = true; enable = true;
vlan = 20; vlan = 20;
address = "10.23.20.110"; address = "10.23.20.110";
allowedHosts = [
"home"
"10.23.20.110"
"10.23.20.110:8082"
];
reverseProxy = { reverseProxy = {
enable = true; enable = true;
route = { route = {

View File

@@ -6,6 +6,7 @@
}: }:
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}";
@@ -90,6 +91,26 @@ 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 (
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
);
derivedAllowedHosts = lib.unique (
matchingDomains
++ matchingAddresses
++ map (address: "${address}:${toString cfg.listenPort}") matchingAddresses
);
in in
{ {
options.modules.services.homepage = { options.modules.services.homepage = {
@@ -102,9 +123,9 @@ in
}; };
allowedHosts = lib.mkOption { allowedHosts = lib.mkOption {
type = lib.types.listOf lib.types.str; type = lib.types.nullOr (lib.types.listOf lib.types.str);
default = [ "home" ]; default = null;
description = "Host headers accepted by Homepage."; description = "Host headers accepted by Homepage. Defaults to matching address and route registry entries.";
}; };
}; };
@@ -113,7 +134,7 @@ in
enable = true; enable = true;
openFirewall = true; openFirewall = true;
inherit (cfg) listenPort; inherit (cfg) listenPort;
allowedHosts = lib.concatStringsSep "," cfg.allowedHosts; allowedHosts = lib.concatStringsSep "," (if cfg.allowedHosts == null then derivedAllowedHosts else cfg.allowedHosts);
services = homepageServices; services = homepageServices;
settings = { settings = {
title = "Tracion"; title = "Tracion";