]> Git — Sourcephile - sourcephile-nix.git/blob - hosts/losurdo/transmission.nix
gitolite: update
[sourcephile-nix.git] / hosts / losurdo / transmission.nix
1 { pkgs, lib, config, hostName, ... }:
2 let
3 inherit (config.services) transmission;
4 inherit (config.users) users;
5 inherit (config.security) gnupg;
6 netns = "riseup";
7 in
8 {
9 users.groups.transmission.members = [
10 users."julm".name
11 ];
12 services.netns.namespaces.${netns}.nftables = ''
13 add rule inet filter input tcp dport ${toString transmission.settings.peer-port} counter accept comment "Transmission"
14 add rule inet filter input udp dport ${toString transmission.settings.peer-port} counter accept comment "Transmission"
15 add rule inet filter output meta skuid ${transmission.user} counter accept comment "Transmission"
16 '';
17 #users.groups.keys.members = [ transmission.user ];
18 security.gnupg.secrets."transmission/settings.json" = {
19 user = transmission.user;
20 systemdConfig.before = [ "transmission.service" ];
21 systemdConfig.wantedBy = [ "transmission.service" ];
22 };
23 fileSystems."/var/lib/transmission" = {
24 device = "${hostName}/var/torrents";
25 fsType = "zfs";
26 };
27 systemd.services.transmission = {
28 after = [
29 "netns-${netns}.service"
30 "zfs.target"
31 ];
32 requires = [
33 "netns-${netns}.service"
34 "zfs.target"
35 ];
36 startAt = "20:00:00";
37 serviceConfig.NetworkNamespacePath = "/var/run/netns/${netns}";
38 };
39 systemd.sockets.proxy-to-transmission = {
40 wantedBy = ["sockets.target"];
41 listenStreams = ["192.168.42.2:9091"];
42 socketConfig.FreeBind = true;
43 };
44 systemd.services.proxy-to-transmission = {
45 requires = ["transmission.service"];
46 after = ["transmission.service" "proxy-to-transmission.socket"];
47 unitConfig.JoinsNamespaceOf = ["transmission.service"];
48 serviceConfig = {
49 ExecStart = "${pkgs.systemd}/lib/systemd/systemd-socket-proxyd 127.0.0.1:9091";
50 PrivateNetwork = true;
51 PrivateTmp = true;
52 };
53 };
54 systemd.services.stop-transmission = {
55 serviceConfig.Type = "oneshot";
56 unitConfig.Conflicts = ["transmission.service"];
57 startAt = "06..19:0,15,30,45:00";
58 script = "true";
59 };
60 services.transmission = {
61 enable = true;
62 performanceNetParameters = true;
63 credentialsFile = gnupg.secrets."transmission/settings.json".path;
64 settings = {
65 message-level = 2;
66 download-dir = "/var/lib/transmission/downloaded";
67 incomplete-dir = "/var/lib/transmission/.incoming";
68 incomplete-dir-enabled = true;
69 watch-dir = "/var/lib/transmission/.torrents";
70 watch-dir-enabled = true;
71 trash-original-torrent-files = false;
72 preallocation = 0;
73 umask = 7; # 007 octal, in decimal!
74 download-queue-enabled = true;
75 download-queue-size = 5;
76 peer-id-ttl-hours = 6;
77 peer-limit-global = 1000;
78 peer-limit-per-torrent = 100;
79
80 peer-port = 6882;
81 peer-port-random-on-start = false;
82 encryption = 1;
83 dht-enabled = true;
84 lpd-enabled = false;
85 pex-enabled = true;
86 port-forwarding-enabled = true;
87 scrape-paused-torrents-enabled = false;
88 peer-socket-tos = "lowcost";
89 queue-stalled-enabled = true;
90 queue-stalled-minutes = 30;
91 speed-limit-down-enabled = false;
92 speed-limit-up = 50;
93 speed-limit-up-enabled = true;
94 alt-speed-enabled = true;
95 alt-speed-time-enabled = true;
96 alt-speed-down = 1000;
97 alt-speed-up = 0;
98 alt-speed-time-day = 127; # all days. 65; # weekend only
99 alt-speed-time-begin = 360; # 06h00 local time
100 alt-speed-time-end = 1260; # 21h00 local time
101 ratio-limit = 4;
102 ratio-limit-enabled = true;
103
104 rpc-enabled = true;
105 rpc-bind-address = "127.0.0.1";
106 rpc-port = 9091;
107 rpc-whitelist = "127.0.0.1,192.168.42.0/24";
108 rpc-whitelist-enabled = true;
109 rpc-host-whitelist = "localhost,${hostName}.wg";
110 rpc-host-whitelist-enabled = true;
111 rpc-authentication-required = true;
112 };
113 };
114 }