self-hosting/modules/torrents.nix

190 lines
5.4 KiB
Nix
Raw Normal View History

2024-12-10 11:39:55 +01:00
{
config,
lib,
2025-03-04 02:05:02 +01:00
pkgs-unstable,
2024-12-10 11:39:55 +01:00
...
}:
let
cfg = config.custom.services.torrents;
in
{
2024-03-26 23:37:53 +01:00
options.custom.services.torrents = {
enable = lib.mkEnableOption "torrents";
2021-12-10 03:02:34 +01:00
};
2024-03-26 23:37:53 +01:00
config = lib.mkIf cfg.enable {
sops.secrets = {
2025-12-24 00:50:36 +01:00
vpnWireguardConfig = {
key = "wireguard/torrents.conf";
2024-12-10 11:39:55 +01:00
};
transmissionRpcCredentials = {
key = "transmission/rpc_config.json";
};
2024-03-26 23:37:53 +01:00
};
2021-12-10 03:02:34 +01:00
2024-03-26 23:37:53 +01:00
containers.torrents = {
ephemeral = true;
autoStart = true;
enableTun = true;
2021-12-10 03:02:34 +01:00
2024-03-26 23:37:53 +01:00
privateNetwork = true;
hostAddress = "192.168.1.1";
localAddress = "192.168.1.2";
bindMounts = {
2025-12-24 00:50:36 +01:00
"${config.sops.secrets.vpnWireguardConfig.path}" = {
hostPath = config.sops.secrets.vpnWireguardConfig.path;
2024-03-26 23:37:53 +01:00
};
"${config.sops.secrets.transmissionRpcCredentials.path}" = {
hostPath = config.sops.secrets.transmissionRpcCredentials.path;
};
"/nix/var/data/media" = {
hostPath = "/nix/var/data/media";
isReadOnly = false;
};
"/nix/var/data/jackett" = {
hostPath = "/nix/var/data/jackett";
isReadOnly = false;
};
"/nix/var/data/sonarr" = {
hostPath = "/nix/var/data/sonarr";
isReadOnly = false;
};
"/nix/var/data/radarr" = {
hostPath = "/nix/var/data/radarr";
isReadOnly = false;
};
"/nix/var/data/lidarr" = {
hostPath = "/nix/var/data/lidarr";
isReadOnly = false;
};
"/nix/var/data/transmission" = {
hostPath = "/nix/var/data/transmission";
isReadOnly = false;
};
2023-09-07 16:19:23 +02:00
};
2024-03-26 23:37:53 +01:00
config = {
time.timeZone = "Europe/Amsterdam";
users.users.www-data = {
uid = 993;
isSystemUser = true;
group = config.users.groups.www-data.name;
};
2024-12-10 11:39:55 +01:00
users.groups.www-data = {
gid = 991;
};
2025-12-24 00:50:36 +01:00
networking.wg-quick.interfaces.wg0 = {
configFile = config.sops.secrets.vpnWireguardConfig.path;
autostart = true;
2024-03-26 23:37:53 +01:00
};
services.transmission = {
enable = true;
2025-12-08 20:20:01 +01:00
package = pkgs-unstable.transmission_4;
2024-03-26 23:37:53 +01:00
openRPCPort = true;
user = config.users.users.www-data.name;
group = config.users.groups.www-data.name;
credentialsFile = config.sops.secrets.transmissionRpcCredentials.path;
home = "/nix/var/data/transmission";
settings = {
rpc-bind-address = "0.0.0.0";
rpc-whitelist = "127.0.0.1,192.168.1.1";
rpc-authentication-required = true;
rpc-host-whitelist-enabled = false;
incomplete-dir = "/nix/var/data/transmission/.incomplete";
watch-dir = "/nix/var/data/transmission/watchdir";
download-dir = "/nix/var/data/transmission/downloads";
};
};
2024-07-03 06:22:06 +02:00
# https://github.com/NixOS/nixpkgs/issues/258793
systemd.services.transmission.serviceConfig = {
RootDirectoryStartOnly = lib.mkForce false;
RootDirectory = lib.mkForce "";
};
2024-03-26 23:37:53 +01:00
services.jackett = {
enable = true;
2025-03-04 02:05:02 +01:00
package = pkgs-unstable.jackett;
2024-03-26 23:37:53 +01:00
openFirewall = true;
user = config.users.users.www-data.name;
group = config.users.groups.www-data.name;
dataDir = "/nix/var/data/jackett";
};
services.sonarr = {
enable = true;
openFirewall = true;
user = config.users.users.www-data.name;
group = config.users.groups.www-data.name;
dataDir = "/nix/var/data/sonarr";
};
services.radarr = {
enable = true;
openFirewall = true;
user = config.users.users.www-data.name;
group = config.users.groups.www-data.name;
dataDir = "/nix/var/data/radarr";
};
services.lidarr = {
enable = true;
openFirewall = true;
user = config.users.users.www-data.name;
group = config.users.groups.www-data.name;
dataDir = "/nix/var/data/lidarr";
};
system.stateVersion = "21.11";
2021-12-10 03:02:34 +01:00
};
};
2024-12-10 11:39:55 +01:00
# virtualisation.oci-containers.containers.flaresolverr = {
# image = "ghcr.io/flaresolverr/flaresolverr:v3.3.11";
# environment = {
# "LOG_LEVEL" = "debug";
# "CAPTCHA_SOLVER" = "hcaptcha-solver";
# };
# ports = [ "192.168.1.1:8191:8191" ];
# autoStart = true;
# };
2023-12-15 05:21:09 +01:00
2024-03-26 23:37:53 +01:00
services.nginx.virtualHosts = {
"transmission.${config.networking.domain}" = {
forceSSL = true;
enableACME = true;
2024-12-10 11:39:55 +01:00
locations."/" = {
proxyPass = "http://192.168.1.2:9091";
};
2021-12-10 03:02:34 +01:00
};
2024-03-26 23:37:53 +01:00
"jackett.${config.networking.domain}" = {
forceSSL = true;
enableACME = true;
2024-12-10 11:39:55 +01:00
locations."/" = {
proxyPass = "http://192.168.1.2:9117";
};
2021-12-10 03:02:34 +01:00
};
2024-03-26 23:37:53 +01:00
"sonarr.${config.networking.domain}" = {
forceSSL = true;
enableACME = true;
2024-12-10 11:39:55 +01:00
locations."/" = {
proxyPass = "http://192.168.1.2:8989";
};
2021-12-10 03:02:34 +01:00
};
2024-03-26 23:37:53 +01:00
"radarr.${config.networking.domain}" = {
forceSSL = true;
enableACME = true;
2024-12-10 11:39:55 +01:00
locations."/" = {
proxyPass = "http://192.168.1.2:7878";
};
2021-12-10 03:02:34 +01:00
};
2024-03-26 23:37:53 +01:00
"lidarr.${config.networking.domain}" = {
forceSSL = true;
enableACME = true;
2024-12-10 11:39:55 +01:00
locations."/" = {
proxyPass = "http://192.168.1.2:8686";
};
2023-09-07 16:19:23 +02:00
};
2021-12-10 03:02:34 +01:00
};
};
}