2016-08-21 11:55:46 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
2016-10-20 20:54:38 +02:00
|
|
|
with import <stockholm/lib>;
|
2016-08-21 11:55:46 +02:00
|
|
|
|
|
|
|
let
|
|
|
|
daemon-user = "tor";
|
2016-12-22 15:41:49 +01:00
|
|
|
basicAuth = import <torrent-secrets/auth.nix>;
|
2016-08-21 11:55:46 +02:00
|
|
|
peer-port = 51412;
|
|
|
|
web-port = 8112;
|
|
|
|
daemon-port = 58846;
|
2017-12-28 16:10:07 +01:00
|
|
|
torrent-dir = config.makefu.dl-dir;
|
2016-08-21 11:55:46 +02:00
|
|
|
in {
|
|
|
|
|
|
|
|
users.users = {
|
|
|
|
download = {
|
|
|
|
name = "download";
|
2017-12-28 16:10:07 +01:00
|
|
|
home = torrent-dir;
|
2017-04-24 23:22:13 +02:00
|
|
|
uid = mkDefault (genid "download");
|
2016-08-21 11:55:46 +02:00
|
|
|
createHome = true;
|
|
|
|
useDefaultShell = true;
|
|
|
|
group = "download";
|
|
|
|
openssh.authorizedKeys.keys = [ ];
|
|
|
|
};
|
|
|
|
};
|
2016-08-24 12:16:18 +02:00
|
|
|
|
2016-08-21 11:55:46 +02:00
|
|
|
# todo: race condition, do this after download user has been created
|
|
|
|
system.activationScripts."download-dir-chmod" = ''
|
2016-08-24 12:16:18 +02:00
|
|
|
for i in finished watch torrents; do
|
2017-12-28 16:10:07 +01:00
|
|
|
mkdir -p "${torrent-dir}/$i"
|
|
|
|
chown download:download "${torrent-dir}/$i"
|
|
|
|
chmod 770 "${torrent-dir}/$i"
|
2016-08-21 11:55:46 +02:00
|
|
|
done
|
|
|
|
'';
|
|
|
|
|
|
|
|
users.extraGroups = {
|
|
|
|
download = {
|
2017-04-24 23:22:13 +02:00
|
|
|
gid = lib.mkDefault (genid "download");
|
2016-08-21 11:55:46 +02:00
|
|
|
members = [
|
|
|
|
config.krebs.build.user.name
|
|
|
|
"download"
|
2016-08-24 12:16:18 +02:00
|
|
|
"rtorrent"
|
|
|
|
"nginx"
|
2016-08-21 11:55:46 +02:00
|
|
|
];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2016-08-24 17:51:22 +02:00
|
|
|
krebs.rtorrent = {
|
2016-08-21 11:55:46 +02:00
|
|
|
enable = true;
|
2016-08-24 12:16:18 +02:00
|
|
|
web = {
|
|
|
|
enable = true;
|
2016-12-22 15:41:49 +01:00
|
|
|
port = web-port;
|
|
|
|
inherit basicAuth;
|
2016-08-21 11:55:46 +02:00
|
|
|
};
|
2016-08-24 12:16:18 +02:00
|
|
|
rutorrent.enable = true;
|
|
|
|
enableXMLRPC = true;
|
|
|
|
listenPort = peer-port;
|
2017-12-28 16:10:07 +01:00
|
|
|
workDir = torrent-dir;
|
2016-08-24 12:16:18 +02:00
|
|
|
# dump old torrents into watch folder to have them re-added
|
2016-08-21 11:55:46 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
networking.firewall.extraCommands = ''
|
2016-08-24 12:16:18 +02:00
|
|
|
iptables -A INPUT -i retiolum -p tcp --dport ${toString web-port} -j ACCEPT
|
2016-08-21 11:55:46 +02:00
|
|
|
'';
|
|
|
|
|
|
|
|
networking.firewall.allowedTCPPorts = [ peer-port ];
|
|
|
|
networking.firewall.allowedUDPPorts = [ peer-port ];
|
|
|
|
}
|