nixos/nginx: Add defaultListenAddresses option

Lets you specify the default listen address if none are listed in the vhost configuration.

Useful for hosts with more than one ip
This commit is contained in:
Daniel Olsen 2022-01-24 02:13:00 +01:00
parent 39ea430092
commit ab7e6995ac

View File

@ -245,12 +245,9 @@ let
defaultListen =
if vhost.listen != [] then vhost.listen
else
let addrs = if vhost.listenAddresses != [] then vhost.listenAddresses else (
[ "0.0.0.0" ] ++ optional enableIPv6 "[::0]"
);
in
optionals (hasSSL || vhost.rejectSSL) (map (addr: { inherit addr; port = 443; ssl = true; }) addrs)
++ optionals (!onlySSL) (map (addr: { inherit addr; port = 80; ssl = false; }) addrs);
let addrs = if vhost.listenAddresses != [] then vhost.listenAddresses else cfg.defaultListenAddresses;
in optionals (hasSSL || vhost.rejectSSL) (map (addr: { inherit addr; port = 443; ssl = true; }) addrs)
++ optionals (!onlySSL) (map (addr: { inherit addr; port = 80; ssl = false; }) addrs);
hostListen =
if vhost.forceSSL
@ -432,6 +429,16 @@ in
";
};
defaultListenAddresses = mkOption {
type = types.listOf types.str;
default = [ "0.0.0.0" ] ++ optional enableIPv6 "[::0]";
defaultText = literalExpression ''[ "0.0.0.0" ] ++ lib.optional config.networking.enableIPv6 "[::0]"'';
example = literalExpression ''[ "10.0.0.12" "[2002:a00:1::]" ]'';
description = "
If vhosts do not specify listenAddresses, use these addresses by default.
";
};
package = mkOption {
default = pkgs.nginxStable;
defaultText = literalExpression "pkgs.nginxStable";