Skip to content

Commit

Permalink
rss-bridge: add config option
Browse files Browse the repository at this point in the history
This allows managing rss-bridge's config with nix.
It leverages the environment variable way of setting the config options,
introduced quite [some time ago](RSS-Bridge/rss-bridge#2100)
It is the only existing way to set config options independent of the
document root, and upstream is [hesitant](RSS-Bridge/rss-bridge#3842)
to change the config loading methods.

Co-authored-by: Sandro <sandro.jaeckel@gmail.com>
  • Loading branch information
Mynacol and SuperSandro2000 committed Mar 2, 2024
1 parent b6401f8 commit f220178
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion nixos/modules/services/web-apps/rss-bridge.nix
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,29 @@ in
Use `[ "*" ]` to whitelist all.
'';
};

config = mkOption {
type = with types; attrsOf (attrsOf (oneOf [ bool int str (listOf str) ]));
default = {};
defaultText = options.literalExpression "FileCache.path = \"\${config.services.rss-bridge.dataDir}/cache/\"";
example = options.literalExpression ''
{
system.enabled_bridges = [ "*" ];
error = {
output = "http";
report_limit = 5;
};
FileCache = {
enable_purge = true;
};
}
'';
description = lib.mdDoc ''
Attribute set of arbitrary config options.
Please consult the documentation at the [wiki](https://rss-bridge.github.io/rss-bridge/For_Hosts/Custom_Configuration.html)
and [sample config](https://github.com/RSS-Bridge/rss-bridge/blob/master/config.default.ini.php) to see a list of available options.
'';
};
};
};

Expand Down Expand Up @@ -109,13 +132,25 @@ in
tryFiles = "$uri /index.php$is_args$args";
};

locations."~ ^/index.php(/|$)" = {
locations."~ ^/index.php(/|$)" = let
cfgHalf = lib.mapAttrsRecursive (path: value: let
envName = lib.toUpper ("RSSBRIDGE_" + lib.concatStringsSep "_" path);
envValue = if lib.isList value then
lib.concatStringsSep "," value
else if lib.isBool value then
lib.boolToString value
else
toString value;
in "fastcgi_param \"${envName}\" \"${envValue}\";") cfg.config;
cfgEnv = lib.concatStringsSep "\n" (lib.collect lib.isString cfgHalf);
in {
extraConfig = ''
include ${config.services.nginx.package}/conf/fastcgi_params;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:${config.services.phpfpm.pools.${cfg.pool}.socket};
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param RSSBRIDGE_DATA ${cfg.dataDir};
${cfgEnv}
'';
};
};
Expand Down

0 comments on commit f220178

Please sign in to comment.