modules: services: pirate: refactor

This will make adding fail2ban jails easier.
This commit is contained in:
Bruno BELANYI 2023-09-03 12:22:02 +02:00
parent adc4ce9d8a
commit 14bf03e5fd

View file

@ -13,26 +13,44 @@ let
sonarr = 8989;
};
managers = with lib.attrsets;
(mapAttrs
(_: _: {
mkService = service: {
services.${service} = {
enable = true;
group = "media";
})
ports);
};
};
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;
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")
]);
}