Commit f2201789 authored by Mynacol's avatar Mynacol
Browse files

rss-bridge: add config option

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](https://github.com/RSS-Bridge/rss-bridge/pull/2100)
It is the only existing way to set config options independent of the
document root, and upstream is [hesitant](https://github.com/RSS-Bridge/rss-bridge/pull/3842

)
to change the config loading methods.

Co-authored-by: default avatarSandro <sandro.jaeckel@gmail.com>
parent b6401f80
Loading
Loading
Loading
Loading
+36 −1
Original line number Diff line number Diff line
@@ -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.
        '';
      };
    };
  };

@@ -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}
            '';
          };
        };