feat(nixos): add local homepage route
This commit is contained in:
@@ -150,6 +150,11 @@
|
|||||||
address = "10.23.20.110";
|
address = "10.23.20.110";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
registry.local-route.${config.networking.hostName}.homepage = {
|
||||||
|
domain = "home";
|
||||||
|
port = 8082;
|
||||||
|
};
|
||||||
|
|
||||||
guests.copyparty = {
|
guests.copyparty = {
|
||||||
enable = true;
|
enable = true;
|
||||||
vlan = 20;
|
vlan = 20;
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ in
|
|||||||
|
|
||||||
listenPort = lib.mkOption {
|
listenPort = lib.mkOption {
|
||||||
type = lib.types.port;
|
type = lib.types.port;
|
||||||
default = 80;
|
default = 8082;
|
||||||
description = "Port for Homepage to bind to.";
|
description = "Port for Homepage to bind to.";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ let
|
|||||||
|
|
||||||
mkBackend = address: route: "http://${address}:${toString route.port}";
|
mkBackend = address: route: "http://${address}:${toString route.port}";
|
||||||
|
|
||||||
mkVirtualHost = host: entry:
|
mkPublicVirtualHost = host: entry:
|
||||||
let
|
let
|
||||||
compositeEntry = registry.join host entry;
|
compositeEntry = registry.join host entry;
|
||||||
route = compositeEntry.route;
|
route = compositeEntry.route;
|
||||||
@@ -19,6 +19,7 @@ let
|
|||||||
in
|
in
|
||||||
{
|
{
|
||||||
inherit host entry;
|
inherit host entry;
|
||||||
|
registryName = "route";
|
||||||
name = route.domain;
|
name = route.domain;
|
||||||
value = {
|
value = {
|
||||||
forceSSL = true;
|
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 (
|
lib.mapAttrsToList (
|
||||||
host: routes:
|
host: routes:
|
||||||
lib.mapAttrsToList (entry: _route: mkVirtualHost host entry) (
|
lib.mapAttrsToList (entry: _route: mkPublicVirtualHost host entry) (
|
||||||
lib.filterAttrs (_entry: route: route.port != null) routes
|
lib.filterAttrs (_entry: route: route.port != null) routes
|
||||||
)
|
)
|
||||||
) registry.route
|
) 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' (
|
virtualHostsByDomain = lib.foldl' (
|
||||||
acc: virtualHost:
|
acc: virtualHost:
|
||||||
acc
|
acc
|
||||||
@@ -49,7 +76,7 @@ let
|
|||||||
domain: virtualHosts:
|
domain: virtualHosts:
|
||||||
if lib.length virtualHosts > 1 then
|
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
|
else
|
||||||
[ ]
|
[ ]
|
||||||
|
|||||||
25
configs/nixos/registry/local-route.nix
Normal file
25
configs/nixos/registry/local-route.nix
Normal 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.";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user