From ea76a1e48cc7d59a7233a54a717a207f9ab85db4 Mon Sep 17 00:00:00 2001 From: Mirko Lenz Date: Thu, 26 Sep 2024 08:06:18 +0200 Subject: [PATCH] nixos/caddy: add port options --- .../services/web-servers/caddy/default.nix | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/nixos/modules/services/web-servers/caddy/default.nix b/nixos/modules/services/web-servers/caddy/default.nix index 1fcf5ef6de5f..d42998b43e81 100644 --- a/nixos/modules/services/web-servers/caddy/default.nix +++ b/nixos/modules/services/web-servers/caddy/default.nix @@ -1,5 +1,6 @@ { config, + options, lib, pkgs, ... @@ -305,6 +306,23 @@ in ''; }; + httpPort = mkOption { + default = 80; + type = with types; nullOr port; + description = '' + The default port to listen on for HTTP traffic. + ''; + }; + + httpsPort = mkOption { + default = 443; + type = with types; nullOr port; + description = '' + The default port to listen on for HTTPS traffic. + Will also be used for HTTP/3. + ''; + }; + enableReload = mkOption { default = true; type = types.bool; @@ -399,6 +417,18 @@ in services.caddy.globalConfig = '' ${optionalString (cfg.email != null) "email ${cfg.email}"} ${optionalString (cfg.acmeCA != null) "acme_ca ${cfg.acmeCA}"} + ${optionalString ( + !elem cfg.httpPort [ + null + options.services.caddy.httpPort.default + ] + ) "http_port ${cfg.httpPort}"} + ${optionalString ( + !elem cfg.httpsPort [ + null + options.services.caddy.httpsPort.default + ] + ) "https_port ${cfg.httpsPort}"} log { ${cfg.logFormat} }