modules: services: nginx: add 'socket' option

This commit is contained in:
Bruno BELANYI 2023-05-13 20:19:26 +02:00
parent 41df5c01ad
commit 685c571018

View file

@ -45,6 +45,16 @@ let
''; '';
}; };
socket = mkOption {
type = with types; nullOr path;
default = null;
example = "FIXME";
description = ''
The UNIX socket for this virtual host. This option is incompatible
with `port`.
'';
};
sso = { sso = {
enable = mkEnableOption "SSO authentication"; enable = mkEnableOption "SSO authentication";
}; };
@ -185,7 +195,7 @@ in
assertions = [ ] assertions = [ ]
++ (lib.flip builtins.map cfg.virtualHosts ({ subdomain, ... } @ args: ++ (lib.flip builtins.map cfg.virtualHosts ({ subdomain, ... } @ args:
let let
conflicts = [ "port" "root" "redirect" ]; conflicts = [ "port" "root" "socket" "redirect" ];
optionsNotNull = builtins.map (v: args.${v} != null) conflicts; optionsNotNull = builtins.map (v: args.${v} != null) conflicts;
optionsSet = lib.filter lib.id optionsNotNull; optionsSet = lib.filter lib.id optionsNotNull;
in in
@ -260,6 +270,11 @@ in
(lib.optionalAttrs (args.root != null) { (lib.optionalAttrs (args.root != null) {
inherit (args) root; inherit (args) root;
}) })
# Serve to UNIX socket
(lib.optionalAttrs (args.socket != null) {
locations."/".proxyPass =
"http://unix:${args.socket}";
})
# Redirect to a different domain # Redirect to a different domain
(lib.optionalAttrs (args.redirect != null) { (lib.optionalAttrs (args.redirect != null) {
locations."/".return = "301 ${args.redirect}$request_uri"; locations."/".return = "301 ${args.redirect}$request_uri";