2021-01-31 22:32:30 +01:00
|
|
|
# The total autonomous media delivery system.
|
|
|
|
# Relevant link [1].
|
|
|
|
#
|
|
|
|
# [1]: https://youtu.be/I26Ql-uX6AM
|
|
|
|
{ config, lib, ... }:
|
|
|
|
let
|
|
|
|
cfg = config.my.services.pirate;
|
|
|
|
|
|
|
|
ports = {
|
|
|
|
bazarr = 6767;
|
2021-02-16 17:38:48 +01:00
|
|
|
lidarr = 8686;
|
2021-11-05 15:55:20 +01:00
|
|
|
radarr = 7878;
|
2024-09-04 12:07:33 +02:00
|
|
|
readarr = 8787;
|
2021-11-05 15:55:20 +01:00
|
|
|
sonarr = 8989;
|
2021-01-31 22:32:30 +01:00
|
|
|
};
|
|
|
|
|
2023-09-03 12:22:02 +02:00
|
|
|
mkService = service: {
|
|
|
|
services.${service} = {
|
|
|
|
enable = true;
|
|
|
|
group = "media";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
mkRedirection = service: {
|
2023-12-25 19:25:08 +01:00
|
|
|
my.services.nginx.virtualHosts = {
|
|
|
|
${service} = {
|
2023-09-03 12:22:02 +02:00
|
|
|
port = ports.${service};
|
2023-12-25 19:25:08 +01:00
|
|
|
};
|
|
|
|
};
|
2023-09-03 12:22:02 +02:00
|
|
|
};
|
2021-01-31 22:32:30 +01:00
|
|
|
|
2023-10-06 23:11:46 +02:00
|
|
|
mkFail2Ban = service: lib.mkIf cfg.${service}.enable {
|
2023-09-03 12:43:46 +02:00
|
|
|
services.fail2ban.jails = {
|
|
|
|
${service} = ''
|
|
|
|
enabled = true
|
|
|
|
filter = ${service}
|
|
|
|
action = iptables-allports
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
environment.etc = {
|
|
|
|
"fail2ban/filter.d/${service}.conf".text = ''
|
|
|
|
[Definition]
|
|
|
|
failregex = ^.*\|Warn\|Auth\|Auth-Failure ip <HOST> username .*$
|
|
|
|
journalmatch = _SYSTEMD_UNIT=${service}.service
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-10-06 23:11:46 +02:00
|
|
|
mkFullConfig = service: lib.mkIf cfg.${service}.enable (lib.mkMerge [
|
2023-09-03 12:22:02 +02:00
|
|
|
(mkService service)
|
|
|
|
(mkRedirection service)
|
2023-10-06 23:11:46 +02:00
|
|
|
]);
|
2021-01-31 22:32:30 +01:00
|
|
|
in
|
|
|
|
{
|
|
|
|
options.my.services.pirate = {
|
|
|
|
enable = lib.mkEnableOption "Media automation";
|
2023-10-06 23:11:46 +02:00
|
|
|
|
|
|
|
bazarr = {
|
|
|
|
enable = lib.my.mkDisableOption "Bazarr";
|
|
|
|
};
|
|
|
|
|
|
|
|
lidarr = {
|
|
|
|
enable = lib.my.mkDisableOption "Lidarr";
|
|
|
|
};
|
|
|
|
|
|
|
|
radarr = {
|
|
|
|
enable = lib.my.mkDisableOption "Radarr";
|
|
|
|
};
|
|
|
|
|
2024-09-04 12:07:33 +02:00
|
|
|
readarr = {
|
|
|
|
enable = lib.my.mkDisableOption "Readarr";
|
|
|
|
};
|
|
|
|
|
2023-10-06 23:11:46 +02:00
|
|
|
sonarr = {
|
|
|
|
enable = lib.my.mkDisableOption "Sonarr";
|
|
|
|
};
|
2021-01-31 22:32:30 +01:00
|
|
|
};
|
|
|
|
|
2023-09-03 12:22:02 +02:00
|
|
|
config = lib.mkIf cfg.enable (lib.mkMerge [
|
|
|
|
{
|
|
|
|
# Set-up media group
|
|
|
|
users.groups.media = { };
|
|
|
|
}
|
2023-09-03 12:43:46 +02:00
|
|
|
# Bazarr does not log authentication failures...
|
2023-09-03 12:22:02 +02:00
|
|
|
(mkFullConfig "bazarr")
|
|
|
|
# Lidarr for music
|
|
|
|
(mkFullConfig "lidarr")
|
2023-09-03 12:43:46 +02:00
|
|
|
(mkFail2Ban "lidarr")
|
2023-09-03 12:22:02 +02:00
|
|
|
# Radarr for movies
|
|
|
|
(mkFullConfig "radarr")
|
2023-09-03 12:43:46 +02:00
|
|
|
(mkFail2Ban "radarr")
|
2024-09-04 12:07:33 +02:00
|
|
|
# Readarr for books
|
|
|
|
(mkFullConfig "readarr")
|
|
|
|
(mkFail2Ban "readarr")
|
2023-09-03 12:22:02 +02:00
|
|
|
# Sonarr for shows
|
|
|
|
(mkFullConfig "sonarr")
|
2023-09-03 12:43:46 +02:00
|
|
|
(mkFail2Ban "sonarr")
|
2023-09-03 12:22:02 +02:00
|
|
|
]);
|
2021-01-31 22:32:30 +01:00
|
|
|
}
|