nixos/services.deluge: remove `with lib;`

Changed files
+43 -46
nixos
modules
services
torrent
+43 -46
nixos/modules/services/torrent/deluge.nix
···
{ 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);
···
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";
···
'';
};
-
declarative = mkOption {
-
type = types.bool;
+
declarative = lib.mkOption {
+
type = lib.types.bool;
default = false;
description = ''
Whether to use a declarative deluge configuration.
···
'';
};
-
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
···
'';
};
-
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
···
'';
};
-
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,
···
'';
};
-
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
···
};
};
-
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
···
"${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;
};
···
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";
···
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}
'';
···
};
};
-
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;
···
};
};
-
users.groups = mkIf (cfg.group == "deluge") {
+
users.groups = lib.mkIf (cfg.group == "deluge") {
deluge = {
gid = config.ids.gids.deluge;
};