From 14bf03e5fd8f0c9285f131d25b89f6e33799c5df Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sun, 3 Sep 2023 12:22:02 +0200 Subject: [PATCH] modules: services: pirate: refactor This will make adding fail2ban jails easier. --- modules/services/pirate/default.nix | 48 ++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/modules/services/pirate/default.nix b/modules/services/pirate/default.nix index 42dd12b..96f5ad4 100644 --- a/modules/services/pirate/default.nix +++ b/modules/services/pirate/default.nix @@ -13,26 +13,44 @@ let sonarr = 8989; }; - managers = with lib.attrsets; - (mapAttrs - (_: _: { - enable = true; - group = "media"; - }) - ports); + mkService = service: { + services.${service} = { + enable = true; + group = "media"; + }; + }; - redirections = lib.flip lib.mapAttrsToList ports - (subdomain: port: { inherit subdomain port; }); + mkRedirection = service: { + my.services.nginx.virtualHosts = [ + { + subdomain = service; + port = ports.${service}; + } + ]; + }; + + mkFullConfig = service: lib.mkMerge [ + (mkService service) + (mkRedirection service) + ]; in { options.my.services.pirate = { enable = lib.mkEnableOption "Media automation"; }; - config = lib.mkIf cfg.enable { - services = managers; - my.services.nginx.virtualHosts = redirections; - # Set-up media group - users.groups.media = { }; - }; + config = lib.mkIf cfg.enable (lib.mkMerge [ + { + # Set-up media group + users.groups.media = { }; + } + # Bazarr for subtitles + (mkFullConfig "bazarr") + # Lidarr for music + (mkFullConfig "lidarr") + # Radarr for movies + (mkFullConfig "radarr") + # Sonarr for shows + (mkFullConfig "sonarr") + ]); }