···
{ config, lib, pkgs, ... }:
cfg = config.services.deluge;
cfg_web = config.services.deluge.web;
+
isDeluge1 = lib.versionOlder cfg.package.version "2.0.0";
listenPortsDefault = [ 6881 6889 ];
+
listToRange = x: { from = lib.elemAt x 0; to = lib.elemAt x 1; };
configDir = "${cfg.dataDir}/.config/deluge";
configFile = pkgs.writeText "core.conf" (builtins.toJSON cfg.config);
···
+
enable = lib.mkEnableOption "Deluge daemon";
+
openFilesLimit = lib.mkOption {
default = openFilesLimit;
+
type = lib.types.either lib.types.int lib.types.str;
Number of files to allow deluged to open.
+
config = lib.mkOption {
+
type = lib.types.attrs;
+
example = lib.literalExpression ''
download_location = "/srv/torrents/";
max_upload_speed = "1000.0";
···
+
declarative = lib.mkOption {
Whether to use a declarative deluge configuration.
···
+
openFirewall = lib.mkOption {
Whether to open the firewall for the ports in
{option}`services.deluge.config.listen_ports`. It only takes effet if
···
+
dataDir = lib.mkOption {
default = "/var/lib/deluge";
The directory where deluge will create files.
+
authFile = lib.mkOption {
example = "/run/keys/deluge-auth";
The file managing the authentication for deluge, the format of this
···
User account under which deluge runs.
Group under which deluge runs.
+
extraPackages = lib.mkOption {
+
type = lib.types.listOf lib.types.package;
Extra packages available at runtime to enable Deluge's plugins. For example,
···
+
package = lib.mkPackageOption pkgs "deluge-2_x" { };
+
enable = lib.mkEnableOption "Deluge Web daemon";
+
openFirewall = lib.mkOption {
Open ports in the firewall for deluge web daemon
···
+
config = lib.mkIf cfg.enable {
+
services.deluge.package = lib.mkDefault (
+
if lib.versionAtLeast config.system.stateVersion "20.09" then
# deluge-1_x is no longer packaged and this will resolve to an error
···
"${cfg.dataDir}/.config".d = defaultConfig;
"${cfg.dataDir}/.config/deluge".d = defaultConfig;
+
// lib.optionalAttrs (cfg.config ? download_location) {
${cfg.config.download_location}.d = defaultConfig;
+
// lib.optionalAttrs (cfg.config ? torrentfiles_location) {
${cfg.config.torrentfiles_location}.d = defaultConfig;
+
// lib.optionalAttrs (cfg.config ? move_completed_path) {
${cfg.config.move_completed_path}.d = defaultConfig;
···
+
systemd.services.delugeweb = lib.mkIf cfg_web.enable {
after = [ "network.target" "deluged.service"];
requires = [ "deluged.service" ];
description = "Deluge BitTorrent WebUI";
···
${cfg.package}/bin/deluge-web \
+
${lib.optionalString (!isDeluge1) "--do-not-daemonize"} \
--port ${toString cfg.web.port}
···
+
networking.firewall = lib.mkMerge [
+
(lib.mkIf (cfg.declarative && cfg.openFirewall && !(cfg.config.random_port or true)) {
+
allowedTCPPortRanges = lib.singleton (listToRange (cfg.config.listen_ports or listenPortsDefault));
+
allowedUDPPortRanges = lib.singleton (listToRange (cfg.config.listen_ports or listenPortsDefault));
+
(lib.mkIf (cfg.web.openFirewall) {
allowedTCPPorts = [ cfg.web.port ];
environment.systemPackages = [ cfg.package ];
+
users.users = lib.mkIf (cfg.user == "deluge") {
uid = config.ids.uids.deluge;
···
+
users.groups = lib.mkIf (cfg.group == "deluge") {
gid = config.ids.gids.deluge;