feat(nixos): add local homepage route

This commit is contained in:
2026-09-15 19:34:35 -04:00
parent dac78e3426
commit 4f6ade4ed5
4 changed files with 62 additions and 5 deletions

View File

@@ -150,6 +150,11 @@
address = "10.23.20.110";
};
registry.local-route.${config.networking.hostName}.homepage = {
domain = "home";
port = 8082;
};
guests.copyparty = {
enable = true;
vlan = 20;

View File

@@ -72,7 +72,7 @@ in
listenPort = lib.mkOption {
type = lib.types.port;
default = 80;
default = 8082;
description = "Port for Homepage to bind to.";
};

View File

@@ -11,7 +11,7 @@ let
mkBackend = address: route: "http://${address}:${toString route.port}";
mkVirtualHost = host: entry:
mkPublicVirtualHost = host: entry:
let
compositeEntry = registry.join host entry;
route = compositeEntry.route;
@@ -19,6 +19,7 @@ let
in
{
inherit host entry;
registryName = "route";
name = route.domain;
value = {
forceSSL = true;
@@ -27,15 +28,41 @@ let
};
};
generatedVirtualHostList = lib.concatLists (
mkLocalVirtualHost = host: entry:
let
compositeEntry = registry.join host entry;
route = compositeEntry.local-route;
address = compositeEntry.address or (throw "no matching entry in registry.address for ${mkRegistryPath "local-route" host entry}");
in
{
inherit host entry;
registryName = "local-route";
name = route.domain;
value = {
forceSSL = false;
enableACME = false;
locations."/".proxyPass = mkBackend address route;
};
};
generatedPublicVirtualHostList = lib.concatLists (
lib.mapAttrsToList (
host: routes:
lib.mapAttrsToList (entry: _route: mkVirtualHost host entry) (
lib.mapAttrsToList (entry: _route: mkPublicVirtualHost host entry) (
lib.filterAttrs (_entry: route: route.port != null) routes
)
) registry.route
);
generatedLocalVirtualHostList = lib.concatLists (
lib.mapAttrsToList (
host: routes:
lib.mapAttrsToList (entry: _route: mkLocalVirtualHost host entry) routes
) registry.local-route
);
generatedVirtualHostList = generatedPublicVirtualHostList ++ generatedLocalVirtualHostList;
virtualHostsByDomain = lib.foldl' (
acc: virtualHost:
acc
@@ -49,7 +76,7 @@ let
domain: virtualHosts:
if lib.length virtualHosts > 1 then
[
"duplicate route domain ${domain} in ${lib.concatMapStringsSep " and " (virtualHost: mkRegistryPath "route" virtualHost.host virtualHost.entry) virtualHosts}"
"duplicate reverse-proxy domain ${domain} in ${lib.concatMapStringsSep " and " (virtualHost: mkRegistryPath virtualHost.registryName virtualHost.host virtualHost.entry) virtualHosts}"
]
else
[ ]

View File

@@ -0,0 +1,25 @@
{ lib, ... }:
{
checks = [
{
assertion = lib.registry.predicates.uniqueValue (entry: entry.value.domain);
message = "Local route domains must be unique.";
}
];
type = lib.types.submodule {
options = {
domain = lib.mkOption {
type = lib.types.str;
example = "home";
description = "Local HTTP domain served by this route entry.";
};
port = lib.mkOption {
type = lib.types.port;
example = 8082;
description = "Backend TCP port served by the matching address registry entry.";
};
};
};
}