From 4a24f168e3fb44073237d9aca95a97e77bdefa3c Mon Sep 17 00:00:00 2001 From: Quentin Aristote Date: Sun, 27 Nov 2022 17:41:34 +0100 Subject: services: web: rss: make configuration into a module --- modules/rss-bridge.nix | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 modules/rss-bridge.nix (limited to 'modules/rss-bridge.nix') diff --git a/modules/rss-bridge.nix b/modules/rss-bridge.nix new file mode 100644 index 0000000..c7aaf05 --- /dev/null +++ b/modules/rss-bridge.nix @@ -0,0 +1,71 @@ +{ config, lib, pkgs, ... }: + +with lib; +let + cfg = config.services.rss-bridge; + rss-bridge = pkgs.rss-bridge.overrideAttrs (oldAttrs: + oldAttrs // { + installPhase = oldAttrs.installPhase + '' + pushd $out/bridges + ln -sf ${./ParisJazzClubBridge.php} ParisJazzClubBridge.php + ln -sf ${./MaisonDeLaRadioBridge.php} MaisonDeLaRadioBridge.php + ln -sf ${./FipAlbumsBridge.php} FipAlbumsBridge.php + ln -sf ${./WhatsOnMubiBridge.php} WhatsOnMubiBridge.php + popd + '' + lib.optionalString debug '' + touch $out/DEBUG + ''; + }); +in { + options.services.rss-bridge = { + package = mkOption { + type = types.package; + description = "Which derivation to use."; + default = pkgs.rss-bridge; + defaultText = literalExample "pkgs.rss-bridge"; + }; + debug = mkEnableOption "debug mode"; + extraBridges = mkOption { + type = types.listOf (types.submodule { + options = { + name = mkOption { + type = 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 = mkOption { + type = 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 = mkIf (cfg.virtualHost != null) { + virtualHosts.${cfg.virtualHost}.root = mkIf (cfg.extraBridges != [ ]) + (mkForce (pkgs.runCommand "rss-bridge" { } ('' + mkdir -p $out/bridges + cp -r ${cfg.package}/* $out/ + pushd $out/bridges + '' + concatStringsSep "\n" + (map (bridge: ''ln -sf ${bridge.source} "${bridge.name}Bridge.php"'') + cfg.extraBridges) + '' + popd + '' + lib.optionalString cfg.debug '' + touch $out/DEBUG + ''))); + }; +} -- cgit v1.2.3 From d051993c310b11be05c9196db1a5e151b4009bcd Mon Sep 17 00:00:00 2001 From: Quentin Aristote Date: Sun, 27 Nov 2022 17:57:13 +0100 Subject: modules: rss-bridge: fix linking of extra bridges --- modules/rss-bridge.nix | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'modules/rss-bridge.nix') diff --git a/modules/rss-bridge.nix b/modules/rss-bridge.nix index c7aaf05..7acc6a5 100644 --- a/modules/rss-bridge.nix +++ b/modules/rss-bridge.nix @@ -60,12 +60,12 @@ in { mkdir -p $out/bridges cp -r ${cfg.package}/* $out/ pushd $out/bridges - '' + concatStringsSep "\n" - (map (bridge: ''ln -sf ${bridge.source} "${bridge.name}Bridge.php"'') - cfg.extraBridges) + '' - popd - '' + lib.optionalString cfg.debug '' - touch $out/DEBUG - ''))); + '' + concatStrings (map (bridge: '' + ln -sf ${bridge.source} "${bridge.name}Bridge.php" + '') cfg.extraBridges) + '' + popd + '' + lib.optionalString cfg.debug '' + touch $out/DEBUG + ''))); }; } -- cgit v1.2.3 From ed163a6c11d9dc291f074a6d27681617c964a97d Mon Sep 17 00:00:00 2001 From: Quentin Aristote Date: Sun, 27 Nov 2022 18:05:34 +0100 Subject: remove extra whitespace --- modules/rss-bridge.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules/rss-bridge.nix') diff --git a/modules/rss-bridge.nix b/modules/rss-bridge.nix index 7acc6a5..7c0d349 100644 --- a/modules/rss-bridge.nix +++ b/modules/rss-bridge.nix @@ -59,7 +59,7 @@ in { (mkForce (pkgs.runCommand "rss-bridge" { } ('' mkdir -p $out/bridges cp -r ${cfg.package}/* $out/ - pushd $out/bridges + pushd $out/bridges '' + concatStrings (map (bridge: '' ln -sf ${bridge.source} "${bridge.name}Bridge.php" '') cfg.extraBridges) + '' -- cgit v1.2.3