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;
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 {
guests.homepage = {
interior.modules.services.homepage = {
enable = true;
inherit (cfg) allowedHosts;
};
interior.modules.services.homepage.enable = true;
limits = {
memory = lib.mkDefault "1G";

View File

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

View File

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