ma torrent: migrate to upstream rtorrent + flood

This commit is contained in:
makefu 2022-03-01 23:20:22 +01:00
parent 859a1c2101
commit 4904dcf229
No known key found for this signature in database
GPG Key ID: 36F7711F3FC0F225

View File

@ -1,73 +1,48 @@
{ config, lib, pkgs, ... }: { config, lib, pkgs, ... }:
with import <stockholm/lib>;
let let
basicAuth = import <torrent-secrets/auth.nix>; basicAuth = import <torrent-secrets/auth.nix>;
peer-port = 51412; peer-port = 51412;
web-port = 8112; web-port = 8112;
daemon-port = 58846; daemon-port = 58846;
base-dir = config.krebs.rtorrent.workDir; dldir = config.makefu.dl-dir;
in { in {
services.rtorrent.enable = true;
services.rtorrent.user = "rtorrent";
services.rtorrent.group = "download";
services.rtorrent.downloadDir = dldir;
services.rtorrent.configText = ''
schedule2 = watch_start, 10, 10, ((load.start, (cat, (cfg.watch), "/media/cloud/watch/*.torrent")))
'';
users.users = { services.rtorrent.openFirewall = true;
download = {
name = "download"; systemd.services.flood = {
home = base-dir; wantedBy = [ "multi-user.target" ];
uid = mkDefault (genid "download"); wants = [ "rtorrent.service" ];
createHome = true; after = [ "rtorrent.service" ];
useDefaultShell = true; serviceConfig = {
group = "download"; User = "rtorrent";
openssh.authorizedKeys.keys = [ ]; ExecStart = "${pkgs.nodePackages.flood}/bin/flood --auth none --port ${toString web-port} --rtsocket ${config.services.rtorrent.rpcSocket}";
}; };
}; };
users.extraGroups = { #security.acme.certs."torrent.${config.krebs.build.host.name}.r".server = config.krebs.ssl.acmeURL;
download = {
gid = lib.mkDefault (genid "download");
members = [
config.krebs.build.user.name
"download"
"rtorrent"
"nginx"
];
};
rtorrent.members = [ "download" ];
};
krebs.rtorrent = let services.nginx = {
d = config.makefu.dl-dir;
in {
enable = true; enable = true;
web = { virtualHosts."torrent.${config.krebs.build.host.name}.r" = {
enable = true; # TODO
port = web-port;
inherit basicAuth; inherit basicAuth;
}; #enableACME = true;
rutorrent.enable = true; #addSSL = true;
enableXMLRPC = true; root = "${pkgs.nodePackages.flood}/lib/node_modules/flood/dist/assets";
listenPort = peer-port; locations."/api".extraConfig = ''
downloadDir = d + "/finished/incoming"; proxy_pass http://localhost:${toString web-port};
watchDir = d + "/watch";
# TODO: maybe test out multiple watch dirs with tags: https://github.com/rakshasa/rtorrent/wiki/TORRENT-Watch-directories
extraConfig = ''
# log.add_output = "debug", "rtorrent-systemd"
# log.add_output = "dht_debug", "rtorrent-systemd"
# log.add_output = "tracker_debug", "rtorrent-systemd"
log.add_output = "rpc_events", "rtorrent-systemd"
# log.add_output = "rpc_dump", "rtorrent-systemd"
system.daemon.set = true
''; '';
# dump old torrents into watch folder to have them re-added locations."/".extraConfig = ''
}; try_files $uri /index.html;
services.nginx.virtualHosts."torrent.${config.krebs.build.host.name}.r".locations."/" = { proxyPass = "http://localhost:${toString web-port}/"; };
networking.firewall.extraCommands = ''
iptables -A INPUT -i retiolum -p tcp --dport ${toString web-port} -j ACCEPT
''; '';
};
networking.firewall.allowedTCPPorts = [ peer-port ]; };
networking.firewall.allowedUDPPorts = [ peer-port ];
state = [ config.krebs.rtorrent.sessionDir ]; # state which torrents were loaded
} }