summaryrefslogtreecommitdiffstats
path: root/makefu/3modules/deluge.nix
blob: 8097885b143294dc5b8e54425376520a4a46cd05 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
{ config, lib, pkgs, ... }:
# based on <nixpkgs>/nixos/modules/services/torrent/deluge.nix
with config.krebs.lib;

let
  cfg_daemon = config.makefu.deluge;
  homedir = cfg_daemon.homedir;
  cfg_web = config.makefu.deluge.web;
  core_conf = pkgs.writeText "deluge-core-cfg" ''
    {
      "file": 1,
      "format": 1
    }${builtins.toJSON (recursiveUpdate default_core_cfg cfg_daemon.cfg)}
  '';

  default_core_cfg = {
    # ports and networking
    daemon_port = 58846; allow_remote = false;
    listen_ports = [ 0 0 ]; # from -> to, 0 -> random
    outgoing_ports = [ 0 0 ];
    random_port = true;
    random_outgoing_ports = true;
    listen_interface = "";
    # folders
    move_completed_path = homedir +"/complete"; move_completed = false;
    autoadd_location = homedir + "/watch"; autoadd_enable = true;
    download_location = homedir + "/data";
    torrentfiles_location = homedir + "/torrents"; copy_torrent_file = false; del_copy_torrent_file = false;
    plugins_location = homedir + "/.config/deluge/plugins"; enabled_plugins = [];
    geoip_db_location = pkgs.geolite-legacy + "/share/GeoIP/GeoIP.dat";
    queue_new_to_top = false;
    info_sent = 0;
    send_info = false;
    compact_allocation = false;
    # peer discovery, extras
    lsd = true;
    natpmp = true;
    utpex = false;
    dht = false;
    upnp = true;
    peer_tos = "0x08";
    # active torrents
    dont_count_slow_torrents = false;
    max_active_limit = -1;
    max_active_downloading = -1;
    max_active_seeding = -1;
    max_upload_slots_global = -1;
    # seeding
    share_ratio_limit = -1;
    seed_time_ratio_limit = -1;
    seed_time_limit = 180;
    stop_seed_at_ratio = false;
    remove_seed_at_ratio = false;
    stop_seed_ratio = 2;
    # speed and connections
    rate_limit_ip_overhead = true;
    ignore_limits_on_local_network = true;
    max_download_speed = -1;
    max_upload_speed = -1;
    max_upload_speed_per_torrent = -1;
    max_download_speed_per_torrent = -1;
    max_half_open_connections = -1;
    max_connections_global = -1;
    max_connections_per_second = -1;
    max_connections_per_torrent = -1;
    max_upload_slots_per_torrent = -1;
    enc_in_policy = 1;
    enc_prefer_rc4 = true;
    enc_level = 2;
    enc_out_policy = 1;
    cache_size = 8192;
    cache_expiry = 60;
    prioritize_first_last_pieces = false;
    auto_managed = true;
    proxies = {
      peer = {
        username = "";
        password = "";
        hostname = "";
        type = 0;
        port = 8080;
      };
      web_seed = {
        username = "";
        password = "";
        hostname = "";
        type = 0;
        port = 8080;
      };
      tracker = {
        username = "";
        password = "";
        hostname = "";
        type = 0;
        port = 8080;
      };
      dht = {
        username = "";
        password = "";
        hostname = "";
        type = 0;
        port = 8080;
      };
    };
    add_paused = false;
    new_release_check = false;
  };

  api = {
      enable = mkEnableOption "deluge daemon";

      cfg = mkOption {
        default = default_core_cfg;
        type = types.attrsOf types.unspecified;
        description = ''
          for full configuration see defaults
        '';
        example = {
          "daemon_port"= 58846;
          "download_location"= "/var/download";
        };
      };

      auth = mkOption {
        default = [];
        example = ["alice:MyC0mpL3xPass:10"];
        type = types.lines;
      };

      homedir = mkOption {
        default = "/var/lib/deluge";
        description = "Home directory of deluge user";
        type = types.str;
      };

      web = {
        enable = mkEnableOption "deluge web";
      };
    };
  imp = {

    systemd.services.deluged = {
      after = [ "network.target" ];
      description = "Deluge BitTorrent Daemon";
      wantedBy = [ "multi-user.target" ];
      serviceConfig = {
        ExecStart = "${pkgs.pythonPackages.deluge}/bin/deluged -d";
        ExecStartPre = pkgs.writeDash "deluged-init" ''
          mkdir -p ${homedir}/.config/deluge
          cp ${core_conf} ${homedir}/.config/deluge/core.conf
        '';
        Restart = "on-success";
        User = "deluge";
        Group = "deluge";
      };
    };

    systemd.services.delugeweb = mkIf cfg_web.enable {
      after = [ "network.target" ];
      description = "Deluge BitTorrent WebUI";
      wantedBy = [ "multi-user.target" ];
      serviceConfig.ExecStart = "${pkgs.pythonPackages.deluge}/bin/deluge --ui web";
      serviceConfig.User = "deluge";
      serviceConfig.Group = "deluge";
    };

    environment.systemPackages = [ pkgs.pythonPackages.deluge ];

    users.extraUsers.deluge = {
      group = "deluge";
      uid = config.ids.uids.deluge;
      home = cfg_daemon.homedir;
      createHome = true;
      description = "Deluge Daemon user";
    };

    users.extraGroups.deluge.gid = config.ids.gids.deluge;
  };
in {
  options.makefu.deluge = api;
  config = lib.mkIf cfg_daemon.enable imp;
}