summaryrefslogtreecommitdiff
path: root/modules/nixos/rss-bridge.nix
blob: 8974ae60ea1c479aff57a5fe3c9c5d8eb9856c47 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
{ config, lib, pkgs, ... }:

let cfg = config.services.rss-bridge;
in {
  options.services.rss-bridge = {
    package = lib.mkOption {
      type = lib.types.package;
      description = "Which derivation to use.";
      default = pkgs.rss-bridge;
      defaultText = lib.literalExample "pkgs.rss-bridge";
    };
    debug = lib.mkEnableOption "debug mode";
    extraBridges = lib.mkOption {
      type = lib.types.listOf (lib.types.submodule {
        options = {
          name = lib.mkOption {
            type = lib.types.strMatching "[a-zA-Z0-9]*";
            description = ''
              The name of the bridge.
              It need not include 'Bridge' at the end, unlike required in RSS-Bridge.
            '';
            example = "SomeAppWithANewsletter";
          };
          source = lib.mkOption {
            type = lib.types.path;
            description = ''
              The path to a file whose contents is the PHP sourcecode of the bridge.
              See also the RSS-Bridge documentation: https://rss-bridge.github.io/rss-bridge/Bridge_API/index.html.
            '';
          };
        };
      });
      default = [ ];
      description = ''
        A list of additional bridges that aren't already included in RSS-Bridge.
        These bridges are automatically whitelisted'';
    };
  };

  config.services.rss-bridge.whitelist =
    map (bridge: bridge.name) cfg.extraBridges;
  config.services.nginx = lib.mkIf (cfg.virtualHost != null) {
    virtualHosts.${cfg.virtualHost}.root = lib.mkIf (cfg.extraBridges != [ ])
      (lib.mkForce (pkgs.runCommand "rss-bridge" { } (''
        mkdir -p $out/bridges
        cp -r ${cfg.package}/* $out/
        pushd $out/bridges
      '' + lib.concatStrings (map (bridge: ''
        ln -sf ${bridge.source} "${bridge.name}Bridge.php"
      '') cfg.extraBridges) + ''
        popd
      '' + lib.optionalString cfg.debug ''
        touch $out/DEBUG
      '')));
  };
}