From 3cade1b5aca8637714c8705d05d31b1ed9aebfec Mon Sep 17 00:00:00 2001 From: Felix Buehler Date: Mon, 10 Feb 2025 23:30:07 +0100 Subject: [PATCH] nixos/rss-bridge: add webserver option Co-authored-by: Zitrone --- .../manual/release-notes/rl-2505.section.md | 2 +- .../modules/services/web-apps/rss-bridge.nix | 41 +++++++++++++++---- 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/nixos/doc/manual/release-notes/rl-2505.section.md b/nixos/doc/manual/release-notes/rl-2505.section.md index cbd051dbeb54..6e0951a1ed2b 100644 --- a/nixos/doc/manual/release-notes/rl-2505.section.md +++ b/nixos/doc/manual/release-notes/rl-2505.section.md @@ -463,7 +463,7 @@ - `networking.wireguard` now has an optional networkd backend. It is enabled by default when `networking.useNetworkd` is enabled, and it can be enabled alongside scripted networking with `networking.wireguard.useNetworkd`. Some `networking.wireguard` options have slightly different behavior with the networkd and script-based backends, documented in each option. -- `services.rss-bridge` now has a `package` option. +- `services.rss-bridge` now has a `package` option as well as support for `caddy` as reverse proxy. - `services.avahi.ipv6` now defaults to true. diff --git a/nixos/modules/services/web-apps/rss-bridge.nix b/nixos/modules/services/web-apps/rss-bridge.nix index fff760b0199b..d847f6005309 100644 --- a/nixos/modules/services/web-apps/rss-bridge.nix +++ b/nixos/modules/services/web-apps/rss-bridge.nix @@ -18,7 +18,6 @@ let cfg = config.services.rss-bridge; - cfgEnv = lib.pipe cfg.config [ (lib.mapAttrsRecursive ( path: value: @@ -61,17 +60,19 @@ in user = mkOption { type = types.str; - default = "nginx"; + default = if cfg.webserver == null then "rss-bridge" else cfg.webserver; + defaultText = "{option}`config.services.rss-bridge.webserver` or \"rss-bridge\""; description = '' - User account under which both the service and the web-application run. + The user account under which both the service and the web application run. ''; }; group = mkOption { type = types.str; - default = "nginx"; + default = if cfg.webserver == null then "rss-bridge" else cfg.webserver; + defaultText = "{option}`config.services.rss-bridge.webserver` or \"rss-bridge\""; description = '' - Group under which the web-application run. + The group under which the web application runs. ''; }; @@ -99,7 +100,20 @@ in type = types.nullOr types.str; default = "rss-bridge"; description = '' - Name of the nginx virtualhost to use and setup. If null, do not setup any virtualhost. + Name of the nginx or caddy virtualhost to use and setup. If null, do not setup any virtualhost. + ''; + }; + + webserver = mkOption { + type = types.nullOr ( + types.enum [ + "nginx" + "caddy" + ] + ); + default = "nginx"; + description = '' + Type of virtualhost to use and setup. If null, do not setup any virtualhost. ''; }; @@ -172,7 +186,7 @@ in }; }; - services.nginx = mkIf (cfg.virtualHost != null) { + services.nginx = mkIf (cfg.virtualHost != null && cfg.webserver == "nginx") { enable = true; virtualHosts = { ${cfg.virtualHost} = { @@ -194,6 +208,19 @@ in }; }; }; + + services.caddy = mkIf (cfg.virtualHost != null && cfg.webserver == "caddy") { + enable = true; + virtualHosts.${cfg.virtualHost} = { + extraConfig = '' + root * ${cfg.package} + file_server + php_fastcgi unix/${config.services.phpfpm.pools.${cfg.pool}.socket} { + ${lib.concatStringsSep "\n" (lib.mapAttrsToList (n: v: " env ${n} \"${v}\"") cfgEnv)} + } + ''; + }; + }; }; meta.maintainers = with lib.maintainers; [ quantenzitrone ];