From 685c571018b0328c49065eaee5aa77bc0931be19 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sat, 13 May 2023 20:19:26 +0200 Subject: [PATCH] modules: services: nginx: add 'socket' option --- modules/services/nginx/default.nix | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/modules/services/nginx/default.nix b/modules/services/nginx/default.nix index 944cd18..dcaaa0f 100644 --- a/modules/services/nginx/default.nix +++ b/modules/services/nginx/default.nix @@ -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 = { enable = mkEnableOption "SSO authentication"; }; @@ -185,7 +195,7 @@ in assertions = [ ] ++ (lib.flip builtins.map cfg.virtualHosts ({ subdomain, ... } @ args: let - conflicts = [ "port" "root" "redirect" ]; + conflicts = [ "port" "root" "socket" "redirect" ]; optionsNotNull = builtins.map (v: args.${v} != null) conflicts; optionsSet = lib.filter lib.id optionsNotNull; in @@ -260,6 +270,11 @@ in (lib.optionalAttrs (args.root != null) { inherit (args) root; }) + # Serve to UNIX socket + (lib.optionalAttrs (args.socket != null) { + locations."/".proxyPass = + "http://unix:${args.socket}"; + }) # Redirect to a different domain (lib.optionalAttrs (args.redirect != null) { locations."/".return = "301 ${args.redirect}$request_uri";