diff --git a/nixos/modules/services/torrent/deluge.nix b/nixos/modules/services/torrent/deluge.nix index 90573fea57b3..4d7d59175ded 100644 --- a/nixos/modules/services/torrent/deluge.nix +++ b/nixos/modules/services/torrent/deluge.nix @@ -1,16 +1,13 @@ { config, lib, pkgs, ... }: - -with lib; - let cfg = config.services.deluge; cfg_web = config.services.deluge.web; - isDeluge1 = versionOlder cfg.package.version "2.0.0"; + isDeluge1 = lib.versionOlder cfg.package.version "2.0.0"; openFilesLimit = 4096; listenPortsDefault = [ 6881 6889 ]; - listToRange = x: { from = elemAt x 0; to = elemAt x 1; }; + 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); @@ -37,20 +34,20 @@ in { options = { services = { deluge = { - enable = mkEnableOption "Deluge daemon"; + enable = lib.mkEnableOption "Deluge daemon"; - openFilesLimit = mkOption { + openFilesLimit = lib.mkOption { default = openFilesLimit; - type = types.either types.int types.str; + type = lib.types.either lib.types.int lib.types.str; description = '' Number of files to allow deluged to open. ''; }; - config = mkOption { - type = types.attrs; + config = lib.mkOption { + type = lib.types.attrs; default = {}; - example = literalExpression '' + example = lib.literalExpression '' { download_location = "/srv/torrents/"; max_upload_speed = "1000.0"; @@ -70,8 +67,8 @@ in { ''; }; - declarative = mkOption { - type = types.bool; + declarative = lib.mkOption { + type = lib.types.bool; default = false; description = '' Whether to use a declarative deluge configuration. @@ -83,9 +80,9 @@ in { ''; }; - openFirewall = mkOption { + openFirewall = lib.mkOption { default = false; - type = types.bool; + type = lib.types.bool; description = '' Whether to open the firewall for the ports in {option}`services.deluge.config.listen_ports`. It only takes effet if @@ -99,16 +96,16 @@ in { ''; }; - dataDir = mkOption { - type = types.path; + dataDir = lib.mkOption { + type = lib.types.path; default = "/var/lib/deluge"; description = '' The directory where deluge will create files. ''; }; - authFile = mkOption { - type = types.path; + authFile = lib.mkOption { + type = lib.types.path; example = "/run/keys/deluge-auth"; description = '' The file managing the authentication for deluge, the format of this @@ -121,24 +118,24 @@ in { ''; }; - user = mkOption { - type = types.str; + user = lib.mkOption { + type = lib.types.str; default = "deluge"; description = '' User account under which deluge runs. ''; }; - group = mkOption { - type = types.str; + group = lib.mkOption { + type = lib.types.str; default = "deluge"; description = '' Group under which deluge runs. ''; }; - extraPackages = mkOption { - type = types.listOf types.package; + extraPackages = lib.mkOption { + type = lib.types.listOf lib.types.package; default = []; description = '' Extra packages available at runtime to enable Deluge's plugins. For example, @@ -147,22 +144,22 @@ in { ''; }; - package = mkPackageOption pkgs "deluge-2_x" { }; + package = lib.mkPackageOption pkgs "deluge-2_x" { }; }; deluge.web = { - enable = mkEnableOption "Deluge Web daemon"; + enable = lib.mkEnableOption "Deluge Web daemon"; - port = mkOption { - type = types.port; + port = lib.mkOption { + type = lib.types.port; default = 8112; description = '' Deluge web UI port. ''; }; - openFirewall = mkOption { - type = types.bool; + openFirewall = lib.mkOption { + type = lib.types.bool; default = false; description = '' Open ports in the firewall for deluge web daemon @@ -172,10 +169,10 @@ in { }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { - services.deluge.package = mkDefault ( - if versionAtLeast config.system.stateVersion "20.09" then + services.deluge.package = lib.mkDefault ( + if lib.versionAtLeast config.system.stateVersion "20.09" then pkgs.deluge-2_x else # deluge-1_x is no longer packaged and this will resolve to an error @@ -201,13 +198,13 @@ in { "${cfg.dataDir}/.config".d = defaultConfig; "${cfg.dataDir}/.config/deluge".d = defaultConfig; } - // optionalAttrs (cfg.config ? download_location) { + // lib.optionalAttrs (cfg.config ? download_location) { ${cfg.config.download_location}.d = defaultConfig; } - // optionalAttrs (cfg.config ? torrentfiles_location) { + // lib.optionalAttrs (cfg.config ? torrentfiles_location) { ${cfg.config.torrentfiles_location}.d = defaultConfig; } - // optionalAttrs (cfg.config ? move_completed_path) { + // lib.optionalAttrs (cfg.config ? move_completed_path) { ${cfg.config.move_completed_path}.d = defaultConfig; }; @@ -233,7 +230,7 @@ in { preStart = preStart; }; - systemd.services.delugeweb = mkIf cfg_web.enable { + systemd.services.delugeweb = lib.mkIf cfg_web.enable { after = [ "network.target" "deluged.service"]; requires = [ "deluged.service" ]; description = "Deluge BitTorrent WebUI"; @@ -242,7 +239,7 @@ in { serviceConfig = { ExecStart = '' ${cfg.package}/bin/deluge-web \ - ${optionalString (!isDeluge1) "--do-not-daemonize"} \ + ${lib.optionalString (!isDeluge1) "--do-not-daemonize"} \ --config ${configDir} \ --port ${toString cfg.web.port} ''; @@ -251,19 +248,19 @@ in { }; }; - networking.firewall = mkMerge [ - (mkIf (cfg.declarative && cfg.openFirewall && !(cfg.config.random_port or true)) { - allowedTCPPortRanges = singleton (listToRange (cfg.config.listen_ports or listenPortsDefault)); - allowedUDPPortRanges = singleton (listToRange (cfg.config.listen_ports or listenPortsDefault)); + 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)); }) - (mkIf (cfg.web.openFirewall) { + (lib.mkIf (cfg.web.openFirewall) { allowedTCPPorts = [ cfg.web.port ]; }) ]; environment.systemPackages = [ cfg.package ]; - users.users = mkIf (cfg.user == "deluge") { + users.users = lib.mkIf (cfg.user == "deluge") { deluge = { group = cfg.group; uid = config.ids.uids.deluge; @@ -272,7 +269,7 @@ in { }; }; - users.groups = mkIf (cfg.group == "deluge") { + users.groups = lib.mkIf (cfg.group == "deluge") { deluge = { gid = config.ids.gids.deluge; };