This commit is contained in:
Joakim Repomaa
2025-02-07 20:27:53 +02:00
committed by Joakim Repomaa
parent e0d0c12a8e
commit 6a5789d45b
12 changed files with 27 additions and 33 deletions

View File

@@ -2,21 +2,11 @@
let
cfg = config.modules.webserver;
nginxVhost = options: {
forceSSL = true;
enableACME = true;
acmeRoot = lib.mkIf cfg.acme.dnsChallenge null;
} // options;
nginxProxy = options: {
proxyWebsockets = true;
} // options;
types = {
location = lib.types.submodule {
options = {
proxy = lib.mkOption {
type = lib.types.nullOr lib.types.str;
proxyPort = lib.mkOption {
type = lib.types.nullOr lib.types.int;
default = null;
};
extraConfig = lib.mkOption {
@@ -28,10 +18,6 @@ let
vhost = lib.types.submodule {
options = {
http2 = lib.mkOption {
type = lib.types.bool;
default = true;
};
proxyBuffering = lib.mkOption {
type = lib.types.bool;
default = true;
@@ -74,15 +60,21 @@ in
recommendedOptimisation = true;
virtualHosts = lib.mapAttrs
(_: { proxyBuffering, locations, http2 }: nginxVhost {
inherit http2;
(_: { proxyBuffering, locations }: {
forceSSL = true;
enableACME = true;
http2 = true;
acmeRoot = lib.mkIf cfg.acme.dnsChallenge null;
extraConfig = lib.mkIf (!proxyBuffering) ''
proxy_buffering off;
'';
locations = lib.mapAttrs
(_: { proxy, extraConfig }: lib.mergeAttrsList [
(_: { proxyPort, extraConfig }: lib.mergeAttrsList [
{ inherit extraConfig; }
(if (lib.isString proxy) then (nginxProxy { proxyPass = proxy; }) else { })
(if (lib.isInt proxyPort) then {
proxyWebsockets = true;
proxyPass = "http://localhost:${toString proxyPort}";
} else { })
])
locations;
})