2023-03-18 22:41:29 +00:00
|
|
|
{ config, pkgs, lib, ... }:
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.custom.services.downloads;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
options.custom.services.downloads = {
|
|
|
|
enable = lib.mkEnableOption "downloads";
|
|
|
|
|
|
|
|
metadataPath = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
|
|
|
default = "/var/lib/downloads";
|
|
|
|
};
|
|
|
|
downloadCachePath = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
|
|
|
default = "/var/cache/torrents";
|
|
|
|
};
|
|
|
|
filmsPath = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
|
|
|
};
|
|
|
|
tvPath = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = lib.mkIf cfg.enable {
|
|
|
|
services.caddy = {
|
|
|
|
enable = true;
|
|
|
|
|
|
|
|
virtualHosts = builtins.listToAttrs (builtins.map
|
|
|
|
(x: {
|
2024-08-01 19:16:06 +01:00
|
|
|
name = "${x}.downloads.ts.hillion.co.uk";
|
2023-03-18 22:41:29 +00:00
|
|
|
value = {
|
2024-02-11 22:24:35 +00:00
|
|
|
listenAddresses = [ config.custom.dns.tailscale.ipv4 config.custom.dns.tailscale.ipv6 ];
|
2024-08-01 19:16:06 +01:00
|
|
|
extraConfig = ''
|
|
|
|
reverse_proxy unix//${cfg.metadataPath}/caddy/caddy.sock
|
|
|
|
|
|
|
|
tls {
|
|
|
|
ca https://ca.ts.hillion.co.uk:8443/acme/acme/directory
|
|
|
|
}
|
|
|
|
'';
|
2023-03-18 22:41:29 +00:00
|
|
|
};
|
|
|
|
}) [ "prowlarr" "sonarr" "radarr" "deluge" ]);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
## Wireguard
|
|
|
|
age.secrets."wireguard/downloads".file = ../../secrets/wireguard/downloads.age;
|
|
|
|
age.secrets."deluge/auth" = {
|
|
|
|
file = ../../secrets/deluge/auth.age;
|
|
|
|
owner = "deluge";
|
|
|
|
};
|
|
|
|
|
|
|
|
networking.wireguard.interfaces."downloads" = {
|
|
|
|
privateKeyFile = config.age.secrets."wireguard/downloads".path;
|
|
|
|
ips = [ "10.2.0.2/32" ];
|
|
|
|
peers = [
|
|
|
|
{
|
|
|
|
publicKey = "9nrcUUgwvjNU5Z+EBB0C2cbrhQ3dsCz+zSU83/eqGFY=";
|
|
|
|
endpoint = "138.199.6.177:51820";
|
|
|
|
allowedIPs = [ "0.0.0.0/0" ];
|
|
|
|
}
|
|
|
|
];
|
|
|
|
interfaceNamespace = "downloads";
|
|
|
|
preSetup = "test -f /run/netns/downloads || ip netns add downloads || test -f /run/netns/downloads";
|
|
|
|
};
|
|
|
|
|
|
|
|
## Host User/Directories
|
|
|
|
users.groups = {
|
|
|
|
radarr.gid = config.ids.gids.radarr;
|
|
|
|
deluge.gid = config.ids.gids.deluge;
|
|
|
|
sonarr.gid = config.ids.gids.sonarr;
|
|
|
|
mediaaccess = {
|
|
|
|
gid = config.ids.gids.mediaaccess;
|
|
|
|
members = [ "radarr" "sonarr" "deluge" config.custom.user ];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
users.users =
|
|
|
|
let
|
|
|
|
mkUser = user: {
|
|
|
|
name = user;
|
|
|
|
value = {
|
|
|
|
group = user;
|
|
|
|
home = "${cfg.metadataPath}/${user}";
|
|
|
|
uid = config.ids.uids.${user};
|
|
|
|
createHome = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
users = [ "radarr" "deluge" "sonarr" ];
|
|
|
|
in
|
|
|
|
builtins.listToAttrs (builtins.map mkUser users);
|
|
|
|
|
|
|
|
systemd.tmpfiles.rules = [
|
|
|
|
"d ${cfg.downloadCachePath} 0750 deluge mediaaccess - -"
|
|
|
|
"d ${cfg.filmsPath} 0770 radarr mediaaccess - -"
|
|
|
|
"d ${cfg.tvPath} 0770 sonarr mediaaccess - -"
|
|
|
|
];
|
|
|
|
|
|
|
|
## Container
|
|
|
|
containers."downloads" = {
|
|
|
|
autoStart = true;
|
|
|
|
ephemeral = true;
|
2023-10-21 22:42:26 +01:00
|
|
|
|
|
|
|
additionalCapabilities = [ "CAP_NET_ADMIN" ];
|
2023-03-18 22:41:29 +00:00
|
|
|
extraFlags = [ "--network-namespace-path=/run/netns/downloads" ];
|
|
|
|
|
|
|
|
bindMounts = {
|
|
|
|
"/var/lib/caddy" = { hostPath = "${cfg.metadataPath}/caddy"; isReadOnly = false; };
|
|
|
|
"/var/lib/sonarr" = { hostPath = "${cfg.metadataPath}/sonarr"; isReadOnly = false; };
|
|
|
|
"/var/lib/radarr" = { hostPath = "${cfg.metadataPath}/radarr"; isReadOnly = false; };
|
|
|
|
"/var/lib/deluge" = { hostPath = "${cfg.metadataPath}/deluge"; isReadOnly = false; };
|
|
|
|
"/var/lib/private/prowlarr" = { hostPath = "${cfg.metadataPath}/prowlarr"; isReadOnly = false; };
|
|
|
|
|
|
|
|
"/media/downloads" = { hostPath = cfg.downloadCachePath; isReadOnly = false; };
|
|
|
|
"/media/films" = { hostPath = cfg.filmsPath; isReadOnly = false; };
|
|
|
|
"/media/tv" = { hostPath = cfg.tvPath; isReadOnly = false; };
|
|
|
|
|
|
|
|
"/run/agenix/deluge/auth".hostPath = config.age.secrets."deluge/auth".path;
|
|
|
|
};
|
|
|
|
|
|
|
|
config = (hostConfig: ({ config, pkgs, ... }: {
|
|
|
|
config = {
|
|
|
|
system.stateVersion = "23.05";
|
|
|
|
|
|
|
|
ids = hostConfig.ids;
|
|
|
|
|
|
|
|
users.groups.mediaaccess = {
|
|
|
|
gid = config.ids.gids.mediaaccess;
|
|
|
|
members = [ "radarr" "sonarr" "deluge" ];
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.services.setup-loopback = {
|
|
|
|
description = "Setup container loopback adapter.";
|
|
|
|
before = [ "network.target" ];
|
|
|
|
|
2023-10-21 22:42:26 +01:00
|
|
|
serviceConfig.Type = "oneshot";
|
|
|
|
serviceConfig.RemainAfterExit = true;
|
|
|
|
|
2023-03-18 22:41:29 +00:00
|
|
|
script = with pkgs; "${iproute2}/bin/ip link set up lo";
|
|
|
|
};
|
2024-05-06 00:07:25 +01:00
|
|
|
networking = {
|
|
|
|
nameservers = [ "1.1.1.1" "8.8.8.8" ];
|
|
|
|
hosts = { "127.0.0.1" = builtins.map (x: "${x}.downloads.ts.hillion.co.uk") [ "prowlarr" "sonarr" "radarr" "deluge" ]; };
|
|
|
|
};
|
2023-03-18 22:41:29 +00:00
|
|
|
|
|
|
|
services = {
|
|
|
|
prowlarr.enable = true;
|
|
|
|
|
|
|
|
sonarr = {
|
|
|
|
enable = true;
|
|
|
|
dataDir = "/var/lib/sonarr";
|
|
|
|
};
|
|
|
|
radarr = {
|
|
|
|
enable = true;
|
|
|
|
dataDir = "/var/lib/radarr";
|
|
|
|
};
|
|
|
|
|
|
|
|
deluge = {
|
|
|
|
enable = true;
|
|
|
|
web.enable = true;
|
2024-03-28 22:22:40 +00:00
|
|
|
group = "mediaaccess";
|
2023-03-18 22:41:29 +00:00
|
|
|
|
|
|
|
dataDir = "/var/lib/deluge";
|
|
|
|
authFile = "/run/agenix/deluge/auth";
|
|
|
|
|
|
|
|
declarative = true;
|
|
|
|
config = {
|
|
|
|
download_location = "/media/downloads";
|
|
|
|
max_connections_global = 1024;
|
2024-03-28 22:22:40 +00:00
|
|
|
|
2023-03-18 22:41:29 +00:00
|
|
|
max_upload_speed = 12500;
|
|
|
|
max_download_speed = 25000;
|
2024-03-28 22:22:40 +00:00
|
|
|
|
|
|
|
max_active_seeding = 192;
|
|
|
|
max_active_downloading = 64;
|
|
|
|
max_active_limit = 256;
|
2023-03-18 22:41:29 +00:00
|
|
|
dont_count_slow_torrents = true;
|
2024-03-28 22:22:40 +00:00
|
|
|
|
|
|
|
stop_seed_at_ratio = true;
|
2023-03-18 22:41:29 +00:00
|
|
|
stop_seed_ratio = 2;
|
2024-03-28 22:22:40 +00:00
|
|
|
|
2023-03-18 22:41:29 +00:00
|
|
|
enabled_plugins = [ "Label" ];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
caddy = {
|
|
|
|
enable = true;
|
|
|
|
virtualHosts = builtins.listToAttrs (builtins.map
|
|
|
|
(x: {
|
|
|
|
name = "http://${x.name}.downloads.ts.hillion.co.uk";
|
|
|
|
value = {
|
|
|
|
listenAddresses = [ "127.0.0.1" "unix///var/lib/caddy/caddy.sock" ];
|
|
|
|
extraConfig = "reverse_proxy http://localhost:${toString x.port}";
|
|
|
|
};
|
|
|
|
}) [
|
|
|
|
{ name = "radarr"; port = 7878; }
|
|
|
|
{ name = "sonarr"; port = 8989; }
|
|
|
|
{ name = "prowlarr"; port = 9696; }
|
|
|
|
{ name = "deluge"; port = config.services.deluge.web.port; }
|
|
|
|
]);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
})) config;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|