nixos: services: nginx: add 'websocketsLocations'
This accounts for the overwhelming majority of my usage of `extraConfig`.
This commit is contained in:
parent
ae230b5df7
commit
e9d96138d5
1 changed files with 34 additions and 10 deletions
|
|
@ -17,6 +17,16 @@ let
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
websocketsLocations = mkOption {
|
||||||
|
type = with types; listOf str;
|
||||||
|
default = [ ];
|
||||||
|
example = [ "/socket" ];
|
||||||
|
description = ''
|
||||||
|
Which locations on this virtual host should be configured for
|
||||||
|
websockets.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
port = mkOption {
|
port = mkOption {
|
||||||
type = with types; nullOr port;
|
type = with types; nullOr port;
|
||||||
default = null;
|
default = null;
|
||||||
|
|
@ -108,12 +118,7 @@ in
|
||||||
};
|
};
|
||||||
jellyfin = {
|
jellyfin = {
|
||||||
port = 8096;
|
port = 8096;
|
||||||
extraConfig = {
|
websocketsLocations = [ "/socket" ];
|
||||||
locations."/socket" = {
|
|
||||||
proxyPass = "http://127.0.0.1:8096/";
|
|
||||||
proxyWebsockets = true;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
description = ''
|
description = ''
|
||||||
|
|
@ -195,6 +200,19 @@ in
|
||||||
} configured.
|
} configured.
|
||||||
'';
|
'';
|
||||||
}))
|
}))
|
||||||
|
++ (lib.flip lib.mapAttrsToList cfg.virtualHosts (_: { subdomain, ... } @ args:
|
||||||
|
let
|
||||||
|
proxyPass = [ "port" "socket" ];
|
||||||
|
proxyPassUsed = lib.any (v: args.${v} != null) proxyPass;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
assertion = args.websocketsLocations != [ ] -> proxyPassUsed;
|
||||||
|
message = ''
|
||||||
|
Subdomain '${subdomain}' can only use 'websocketsLocations' with one of ${
|
||||||
|
lib.concatStringsSep ", " (builtins.map (v: "'${v}'") proxyPass)
|
||||||
|
}.
|
||||||
|
'';
|
||||||
|
}))
|
||||||
++ (
|
++ (
|
||||||
let
|
let
|
||||||
ports = lib.my.mapFilter
|
ports = lib.my.mapFilter
|
||||||
|
|
@ -241,6 +259,14 @@ in
|
||||||
virtualHosts =
|
virtualHosts =
|
||||||
let
|
let
|
||||||
domain = config.networking.domain;
|
domain = config.networking.domain;
|
||||||
|
mkProxyPass = { websocketsLocations, ... }: proxyPass:
|
||||||
|
let
|
||||||
|
websockets = lib.genAttrs websocketsLocations (_: {
|
||||||
|
inherit proxyPass;
|
||||||
|
proxyWebsockets = true;
|
||||||
|
});
|
||||||
|
in
|
||||||
|
{ "/" = { inherit proxyPass; }; } // websockets;
|
||||||
mkVHost = ({ subdomain, ... } @ args: lib.nameValuePair
|
mkVHost = ({ subdomain, ... } @ args: lib.nameValuePair
|
||||||
"${subdomain}.${domain}"
|
"${subdomain}.${domain}"
|
||||||
(lib.my.recursiveMerge [
|
(lib.my.recursiveMerge [
|
||||||
|
|
@ -251,8 +277,7 @@ in
|
||||||
}
|
}
|
||||||
# Proxy to port
|
# Proxy to port
|
||||||
(lib.optionalAttrs (args.port != null) {
|
(lib.optionalAttrs (args.port != null) {
|
||||||
locations."/".proxyPass =
|
locations = mkProxyPass args "http://127.0.0.1:${toString args.port}";
|
||||||
"http://127.0.0.1:${toString args.port}";
|
|
||||||
})
|
})
|
||||||
# Serve filesystem content
|
# Serve filesystem content
|
||||||
(lib.optionalAttrs (args.root != null) {
|
(lib.optionalAttrs (args.root != null) {
|
||||||
|
|
@ -260,8 +285,7 @@ in
|
||||||
})
|
})
|
||||||
# Serve to UNIX socket
|
# Serve to UNIX socket
|
||||||
(lib.optionalAttrs (args.socket != null) {
|
(lib.optionalAttrs (args.socket != null) {
|
||||||
locations."/".proxyPass =
|
locations = mkProxyPass args "http://unix:${args.socket}";
|
||||||
"http://unix:${args.socket}";
|
|
||||||
})
|
})
|
||||||
# Redirect to a different domain
|
# Redirect to a different domain
|
||||||
(lib.optionalAttrs (args.redirect != null) {
|
(lib.optionalAttrs (args.redirect != null) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue