1
0
Fork 0
selfhostblocks/modules/services/deluge.nix

287 lines
8.7 KiB
Nix
Raw Normal View History

2023-09-22 22:58:22 +02:00
{ config, pkgs, lib, ... }:
let
cfg = config.shb.deluge;
2024-01-12 08:22:46 +01:00
contracts = pkgs.callPackage ../contracts {};
2023-09-22 22:58:22 +02:00
fqdn = "${cfg.subdomain}.${cfg.domain}";
in
{
options.shb.deluge = {
enable = lib.mkEnableOption "selfhostblocks.deluge";
subdomain = lib.mkOption {
type = lib.types.str;
description = "Subdomain under which deluge will be served.";
example = "ha";
};
domain = lib.mkOption {
type = lib.types.str;
description = "domain under which deluge will be served.";
example = "mydomain.com";
};
2024-01-12 08:22:46 +01:00
ssl = lib.mkOption {
description = "Path to SSL files";
type = lib.types.nullOr contracts.ssl.certs;
default = null;
};
2023-09-22 22:58:22 +02:00
daemonPort = lib.mkOption {
type = lib.types.int;
description = "Deluge daemon port";
default = 58846;
};
daemonListenPorts = lib.mkOption {
type = lib.types.listOf lib.types.int;
description = "Deluge daemon listen ports";
default = [ 6881 6889 ];
};
webPort = lib.mkOption {
type = lib.types.int;
description = "Deluge web port";
default = 8112;
};
proxyPort = lib.mkOption {
2023-11-30 21:06:41 +01:00
description = "If not null, sets up a deluge to forward all traffic to the Proxy listening at that port.";
2023-09-22 22:58:22 +02:00
type = lib.types.nullOr lib.types.int;
default = null;
};
2023-10-19 04:52:35 +02:00
outgoingInterface = lib.mkOption {
2023-11-30 21:06:41 +01:00
description = "If not null, sets up a deluge to bind all outgoing traffic to the given interface.";
2023-10-19 04:52:35 +02:00
type = lib.types.nullOr lib.types.str;
default = null;
};
2023-12-27 16:57:48 +01:00
settings = lib.mkOption {
description = "Deluge operational settings.";
type = lib.types.submodule {
options = {
downloadLocation = lib.mkOption {
type = lib.types.str;
description = "Folder where torrents gets downloaded";
example = "/srv/torrents";
};
max_active_limit = lib.mkOption {
type = lib.types.int;
description = "Maximum Active Limit";
default = 200;
};
max_active_downloading = lib.mkOption {
type = lib.types.int;
description = "Maximum Active Downloading";
default = 30;
};
max_active_seeding = lib.mkOption {
type = lib.types.int;
description = "Maximum Active Seeding";
default = 100;
};
max_connections_global = lib.mkOption {
type = lib.types.int;
description = "Maximum Connections Global";
default = 200;
};
max_connections_per_torrent = lib.mkOption {
type = lib.types.int;
description = "Maximum Connections Per Torrent";
default = 50;
};
max_download_speed = lib.mkOption {
type = lib.types.int;
description = "Maximum Download Speed";
default = 1000;
};
max_download_speed_per_torrent = lib.mkOption {
type = lib.types.int;
description = "Maximum Download Speed Per Torrent";
default = -1;
};
max_upload_slots_global = lib.mkOption {
type = lib.types.int;
description = "Maximum Upload Slots Global";
default = 100;
};
max_upload_slots_per_torrent = lib.mkOption {
type = lib.types.int;
description = "Maximum Upload Slots Per Torrent";
default = 4;
};
max_upload_speed = lib.mkOption {
type = lib.types.int;
description = "Maximum Upload Speed";
default = 200;
};
max_upload_speed_per_torrent = lib.mkOption {
type = lib.types.int;
description = "Maximum Upload Speed Per Torrent";
default = 50;
};
dont_count_slow_torrents = lib.mkOption {
type = lib.types.bool;
description = "Do not count slow torrents towards any limits.";
default = true;
};
};
};
};
extraServiceConfig = lib.mkOption {
type = lib.types.attrsOf lib.types.str;
description = "Extra configuration given to the systemd service file.";
default = {};
example = lib.literalExpression ''
{
MemoryHigh = "512M";
MemoryMax = "900M";
}
'';
2023-09-22 22:58:22 +02:00
};
authEndpoint = lib.mkOption {
2024-05-25 00:01:45 +02:00
type = lib.types.nullOr lib.types.str;
2023-09-22 22:58:22 +02:00
description = "OIDC endpoint for SSO";
example = "https://authelia.example.com";
};
authFile = lib.mkOption {
2023-09-22 22:58:22 +02:00
type = lib.types.path;
description = "File containing auth lines in the format expected by deluge. See https://dev.deluge-torrent.org/wiki/UserGuide/Authentication.";
2023-09-22 22:58:22 +02:00
};
2023-10-13 07:34:00 +02:00
enabledPlugins = lib.mkOption {
type = lib.types.listOf lib.types.str;
description = "Plugins to enable, can include those from additionalPlugins.";
example = ["Label"];
default = [];
};
2023-09-22 22:58:22 +02:00
additionalPlugins = lib.mkOption {
type = lib.types.listOf lib.types.path;
description = "Location of additional plugins. Each item in the list must be the path to the directory containing the plugin .egg file.";
default = [];
2023-09-22 22:58:22 +02:00
};
2023-10-14 06:17:24 +02:00
logLevel = lib.mkOption {
type = lib.types.nullOr (lib.types.enum ["critical" "error" "warning" "info" "debug"]);
description = "Enable logging.";
default = false;
example = true;
};
2023-09-22 22:58:22 +02:00
};
2023-12-27 16:57:48 +01:00
config = lib.mkIf cfg.enable (lib.mkMerge [{
2023-09-22 22:58:22 +02:00
services.deluge = {
enable = true;
declarative = true;
openFirewall = true;
config = {
2023-12-27 16:57:48 +01:00
download_location = cfg.settings.downloadLocation;
2023-09-22 22:58:22 +02:00
allow_remote = true;
daemon_port = cfg.daemonPort;
listen_ports = cfg.daemonListenPorts;
proxy = lib.optionalAttrs (cfg.proxyPort != null) {
force_proxy = true;
hostname = "127.0.0.1";
port = cfg.proxyPort;
proxy_hostnames = true;
proxy_peer_connections = true;
proxy_tracker_connections = true;
type = 4; # HTTP
};
2023-10-19 04:52:35 +02:00
outgoing_interface = cfg.outgoingInterface;
2023-10-13 07:34:00 +02:00
enabled_plugins = cfg.enabledPlugins
++ lib.optional (lib.any (x: x.enable) [
config.shb.arr.radarr
config.shb.arr.sonarr
config.shb.arr.bazarr
config.shb.arr.readarr
config.shb.arr.lidarr
]) "Label";
2023-10-13 07:34:00 +02:00
2023-12-27 16:57:48 +01:00
inherit (cfg.settings)
max_active_limit
max_active_downloading
max_active_seeding
max_connections_global
max_connections_per_torrent
max_download_speed
max_download_speed_per_torrent
2023-10-12 22:36:44 +02:00
2023-12-27 16:57:48 +01:00
max_upload_slots_global
max_upload_slots_per_torrent
max_upload_speed
max_upload_speed_per_torrent
2023-10-12 22:36:44 +02:00
2023-12-27 16:57:48 +01:00
dont_count_slow_torrents;
2023-10-12 22:36:44 +02:00
new_release_check = false;
2023-09-22 22:58:22 +02:00
};
inherit (cfg) authFile;
2023-09-22 22:58:22 +02:00
web.enable = true;
web.port = cfg.webPort;
};
systemd.services.deluged.serviceConfig.ExecStart = lib.mkForce (lib.concatStringsSep " \\\n " ([
"${config.services.deluge.package}/bin/deluged"
"--do-not-daemonize"
"--config ${config.services.deluge.dataDir}/.config/deluge"
] ++ (lib.optional (!(isNull cfg.logLevel)) "-L ${cfg.logLevel}")
));
2023-09-22 22:58:22 +02:00
systemd.tmpfiles.rules =
let
plugins = pkgs.symlinkJoin {
name = "deluge-plugins";
paths = cfg.additionalPlugins;
};
in
[
"L+ ${config.services.deluge.dataDir}/.config/deluge/plugins - - - - ${plugins}"
];
2023-09-22 22:58:22 +02:00
2024-05-25 00:01:45 +02:00
shb.nginx.vhosts = [
2023-09-22 22:58:22 +02:00
{
2024-01-12 08:22:46 +01:00
inherit (cfg) subdomain domain authEndpoint ssl;
upstream = "http://127.0.0.1:${toString config.services.deluge.web.port}";
2024-05-25 00:01:45 +02:00
autheliaRules = lib.mkIf (cfg.authEndpoint != null) [{
domain = fqdn;
policy = "two_factor";
subject = ["group:deluge_user"];
}];
2023-09-22 22:58:22 +02:00
}
];
# We want deluge to create files in the media group and to make those files group readable.
2023-10-19 04:52:10 +02:00
users.users.deluge = {
extraGroups = [ "media" ];
};
systemd.services.deluged.serviceConfig.Group = lib.mkForce "media";
systemd.services.deluged.serviceConfig.UMask = lib.mkForce "0027";
2023-10-19 04:52:10 +02:00
# We backup the whole deluge directory and set permissions for the backup user accordingly.
users.groups.deluge.members = [ "backup" ];
users.groups.media.members = [ "backup" ];
2023-09-22 22:58:22 +02:00
shb.backup.instances.deluge = {
sourceDirectories = [
config.services.deluge.dataDir
];
};
2023-12-27 16:57:48 +01:00
} {
systemd.services.deluged.serviceConfig = cfg.extraServiceConfig;
}]);
2023-09-22 22:58:22 +02:00
}