lol

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

+43 -46
+43 -46
nixos/modules/services/torrent/deluge.nix
··· 1 1 { config, lib, pkgs, ... }: 2 - 3 - with lib; 4 - 5 2 let 6 3 cfg = config.services.deluge; 7 4 cfg_web = config.services.deluge.web; 8 - isDeluge1 = versionOlder cfg.package.version "2.0.0"; 5 + isDeluge1 = lib.versionOlder cfg.package.version "2.0.0"; 9 6 10 7 openFilesLimit = 4096; 11 8 listenPortsDefault = [ 6881 6889 ]; 12 9 13 - listToRange = x: { from = elemAt x 0; to = elemAt x 1; }; 10 + listToRange = x: { from = lib.elemAt x 0; to = lib.elemAt x 1; }; 14 11 15 12 configDir = "${cfg.dataDir}/.config/deluge"; 16 13 configFile = pkgs.writeText "core.conf" (builtins.toJSON cfg.config); ··· 37 34 options = { 38 35 services = { 39 36 deluge = { 40 - enable = mkEnableOption "Deluge daemon"; 37 + enable = lib.mkEnableOption "Deluge daemon"; 41 38 42 - openFilesLimit = mkOption { 39 + openFilesLimit = lib.mkOption { 43 40 default = openFilesLimit; 44 - type = types.either types.int types.str; 41 + type = lib.types.either lib.types.int lib.types.str; 45 42 description = '' 46 43 Number of files to allow deluged to open. 47 44 ''; 48 45 }; 49 46 50 - config = mkOption { 51 - type = types.attrs; 47 + config = lib.mkOption { 48 + type = lib.types.attrs; 52 49 default = {}; 53 - example = literalExpression '' 50 + example = lib.literalExpression '' 54 51 { 55 52 download_location = "/srv/torrents/"; 56 53 max_upload_speed = "1000.0"; ··· 70 67 ''; 71 68 }; 72 69 73 - declarative = mkOption { 74 - type = types.bool; 70 + declarative = lib.mkOption { 71 + type = lib.types.bool; 75 72 default = false; 76 73 description = '' 77 74 Whether to use a declarative deluge configuration. ··· 83 80 ''; 84 81 }; 85 82 86 - openFirewall = mkOption { 83 + openFirewall = lib.mkOption { 87 84 default = false; 88 - type = types.bool; 85 + type = lib.types.bool; 89 86 description = '' 90 87 Whether to open the firewall for the ports in 91 88 {option}`services.deluge.config.listen_ports`. It only takes effet if ··· 99 96 ''; 100 97 }; 101 98 102 - dataDir = mkOption { 103 - type = types.path; 99 + dataDir = lib.mkOption { 100 + type = lib.types.path; 104 101 default = "/var/lib/deluge"; 105 102 description = '' 106 103 The directory where deluge will create files. 107 104 ''; 108 105 }; 109 106 110 - authFile = mkOption { 111 - type = types.path; 107 + authFile = lib.mkOption { 108 + type = lib.types.path; 112 109 example = "/run/keys/deluge-auth"; 113 110 description = '' 114 111 The file managing the authentication for deluge, the format of this ··· 121 118 ''; 122 119 }; 123 120 124 - user = mkOption { 125 - type = types.str; 121 + user = lib.mkOption { 122 + type = lib.types.str; 126 123 default = "deluge"; 127 124 description = '' 128 125 User account under which deluge runs. 129 126 ''; 130 127 }; 131 128 132 - group = mkOption { 133 - type = types.str; 129 + group = lib.mkOption { 130 + type = lib.types.str; 134 131 default = "deluge"; 135 132 description = '' 136 133 Group under which deluge runs. 137 134 ''; 138 135 }; 139 136 140 - extraPackages = mkOption { 141 - type = types.listOf types.package; 137 + extraPackages = lib.mkOption { 138 + type = lib.types.listOf lib.types.package; 142 139 default = []; 143 140 description = '' 144 141 Extra packages available at runtime to enable Deluge's plugins. For example, ··· 147 144 ''; 148 145 }; 149 146 150 - package = mkPackageOption pkgs "deluge-2_x" { }; 147 + package = lib.mkPackageOption pkgs "deluge-2_x" { }; 151 148 }; 152 149 153 150 deluge.web = { 154 - enable = mkEnableOption "Deluge Web daemon"; 151 + enable = lib.mkEnableOption "Deluge Web daemon"; 155 152 156 - port = mkOption { 157 - type = types.port; 153 + port = lib.mkOption { 154 + type = lib.types.port; 158 155 default = 8112; 159 156 description = '' 160 157 Deluge web UI port. 161 158 ''; 162 159 }; 163 160 164 - openFirewall = mkOption { 165 - type = types.bool; 161 + openFirewall = lib.mkOption { 162 + type = lib.types.bool; 166 163 default = false; 167 164 description = '' 168 165 Open ports in the firewall for deluge web daemon ··· 172 169 }; 173 170 }; 174 171 175 - config = mkIf cfg.enable { 172 + config = lib.mkIf cfg.enable { 176 173 177 - services.deluge.package = mkDefault ( 178 - if versionAtLeast config.system.stateVersion "20.09" then 174 + services.deluge.package = lib.mkDefault ( 175 + if lib.versionAtLeast config.system.stateVersion "20.09" then 179 176 pkgs.deluge-2_x 180 177 else 181 178 # deluge-1_x is no longer packaged and this will resolve to an error ··· 201 198 "${cfg.dataDir}/.config".d = defaultConfig; 202 199 "${cfg.dataDir}/.config/deluge".d = defaultConfig; 203 200 } 204 - // optionalAttrs (cfg.config ? download_location) { 201 + // lib.optionalAttrs (cfg.config ? download_location) { 205 202 ${cfg.config.download_location}.d = defaultConfig; 206 203 } 207 - // optionalAttrs (cfg.config ? torrentfiles_location) { 204 + // lib.optionalAttrs (cfg.config ? torrentfiles_location) { 208 205 ${cfg.config.torrentfiles_location}.d = defaultConfig; 209 206 } 210 - // optionalAttrs (cfg.config ? move_completed_path) { 207 + // lib.optionalAttrs (cfg.config ? move_completed_path) { 211 208 ${cfg.config.move_completed_path}.d = defaultConfig; 212 209 }; 213 210 ··· 233 230 preStart = preStart; 234 231 }; 235 232 236 - systemd.services.delugeweb = mkIf cfg_web.enable { 233 + systemd.services.delugeweb = lib.mkIf cfg_web.enable { 237 234 after = [ "network.target" "deluged.service"]; 238 235 requires = [ "deluged.service" ]; 239 236 description = "Deluge BitTorrent WebUI"; ··· 242 239 serviceConfig = { 243 240 ExecStart = '' 244 241 ${cfg.package}/bin/deluge-web \ 245 - ${optionalString (!isDeluge1) "--do-not-daemonize"} \ 242 + ${lib.optionalString (!isDeluge1) "--do-not-daemonize"} \ 246 243 --config ${configDir} \ 247 244 --port ${toString cfg.web.port} 248 245 ''; ··· 251 248 }; 252 249 }; 253 250 254 - networking.firewall = mkMerge [ 255 - (mkIf (cfg.declarative && cfg.openFirewall && !(cfg.config.random_port or true)) { 256 - allowedTCPPortRanges = singleton (listToRange (cfg.config.listen_ports or listenPortsDefault)); 257 - allowedUDPPortRanges = singleton (listToRange (cfg.config.listen_ports or listenPortsDefault)); 251 + networking.firewall = lib.mkMerge [ 252 + (lib.mkIf (cfg.declarative && cfg.openFirewall && !(cfg.config.random_port or true)) { 253 + allowedTCPPortRanges = lib.singleton (listToRange (cfg.config.listen_ports or listenPortsDefault)); 254 + allowedUDPPortRanges = lib.singleton (listToRange (cfg.config.listen_ports or listenPortsDefault)); 258 255 }) 259 - (mkIf (cfg.web.openFirewall) { 256 + (lib.mkIf (cfg.web.openFirewall) { 260 257 allowedTCPPorts = [ cfg.web.port ]; 261 258 }) 262 259 ]; 263 260 264 261 environment.systemPackages = [ cfg.package ]; 265 262 266 - users.users = mkIf (cfg.user == "deluge") { 263 + users.users = lib.mkIf (cfg.user == "deluge") { 267 264 deluge = { 268 265 group = cfg.group; 269 266 uid = config.ids.uids.deluge; ··· 272 269 }; 273 270 }; 274 271 275 - users.groups = mkIf (cfg.group == "deluge") { 272 + users.groups = lib.mkIf (cfg.group == "deluge") { 276 273 deluge = { 277 274 gid = config.ids.gids.deluge; 278 275 };