From a002f5348b3130e1b94336f6d494aa79f0131a23 Mon Sep 17 00:00:00 2001 From: alexion Date: Tue, 15 Sep 2026 20:16:16 -0400 Subject: [PATCH] fix(nixos): derive homepage allowed hosts --- configs/nixos/guests/homepage.nix | 13 +-------- configs/nixos/hosts/pikachu/default.nix | 5 ---- configs/nixos/modules/services/homepage.nix | 29 ++++++++++++++++++--- 3 files changed, 26 insertions(+), 21 deletions(-) diff --git a/configs/nixos/guests/homepage.nix b/configs/nixos/guests/homepage.nix index 2a8b009..7646765 100644 --- a/configs/nixos/guests/homepage.nix +++ b/configs/nixos/guests/homepage.nix @@ -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"; diff --git a/configs/nixos/hosts/pikachu/default.nix b/configs/nixos/hosts/pikachu/default.nix index 7249fe0..47ff374 100644 --- a/configs/nixos/hosts/pikachu/default.nix +++ b/configs/nixos/hosts/pikachu/default.nix @@ -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 = { diff --git a/configs/nixos/modules/services/homepage.nix b/configs/nixos/modules/services/homepage.nix index d0a9960..eaff1d2 100644 --- a/configs/nixos/modules/services/homepage.nix +++ b/configs/nixos/modules/services/homepage.nix @@ -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";