1 { pkgs, lib, config, hostName, inputs, ... }:
3 inherit (config.services) transmission;
4 inherit (config.users) users;
5 inherit (config.security) gnupg;
7 wg-intra-hosts = import (inputs.julm-nix + "/networking/wireguard/wg-intra/hosts.nix");
10 users.groups.transmission.members = [
13 services.netns.namespaces.${netns}.nftables = ''
14 add rule inet filter input tcp dport ${toString transmission.settings.peer-port} counter accept comment "Transmission"
15 add rule inet filter input udp dport ${toString transmission.settings.peer-port} counter accept comment "Transmission"
16 add rule inet filter output meta skuid ${transmission.user} counter accept comment "Transmission"
18 #users.groups.keys.members = [ transmission.user ];
19 security.gnupg.secrets."transmission/settings.json" = {
20 user = transmission.user;
21 systemdConfig.before = [ "transmission.service" ];
22 systemdConfig.wantedBy = [ "transmission.service" ];
24 fileSystems."/var/lib/transmission" = {
25 device = "${hostName}/var/torrents";
28 systemd.services.transmission = {
30 "netns-${netns}.service"
34 "netns-${netns}.service"
38 serviceConfig.NetworkNamespacePath = "/var/run/netns/${netns}";
40 systemd.sockets.proxy-to-transmission = {
41 wantedBy = ["sockets.target"];
42 listenStreams = ["${wg-intra-hosts.${hostName}.ipv4}:9091"];
43 socketConfig.FreeBind = true;
45 systemd.services.proxy-to-transmission = {
46 requires = ["transmission.service"];
47 after = ["transmission.service" "proxy-to-transmission.socket"];
48 unitConfig.JoinsNamespaceOf = ["transmission.service"];
50 ExecStart = "${pkgs.systemd}/lib/systemd/systemd-socket-proxyd 127.0.0.1:9091";
51 PrivateNetwork = true;
55 systemd.services.stop-transmission = {
56 serviceConfig.Type = "oneshot";
57 unitConfig.Conflicts = ["transmission.service"];
58 startAt = "06..19:0,15,30,45:00";
61 services.transmission = {
63 performanceNetParameters = true;
64 credentialsFile = gnupg.secrets."transmission/settings.json".path;
67 download-dir = "/var/lib/transmission/downloaded";
68 incomplete-dir = "/var/lib/transmission/.incoming";
69 incomplete-dir-enabled = true;
70 watch-dir = "/var/lib/transmission/.torrents";
71 watch-dir-enabled = true;
72 trash-original-torrent-files = false;
74 umask = 7; # 007 octal, in decimal!
75 download-queue-enabled = true;
76 download-queue-size = 5;
77 peer-id-ttl-hours = 6;
78 peer-limit-global = 1000;
79 peer-limit-per-torrent = 100;
82 peer-port-random-on-start = false;
87 port-forwarding-enabled = true;
88 scrape-paused-torrents-enabled = false;
89 peer-socket-tos = "lowcost";
90 queue-stalled-enabled = true;
91 queue-stalled-minutes = 30;
92 speed-limit-down-enabled = false;
94 speed-limit-up-enabled = true;
95 alt-speed-enabled = true;
96 alt-speed-time-enabled = true;
97 alt-speed-down = 1000;
99 alt-speed-time-day = 127; # all days. 65; # weekend only
100 alt-speed-time-begin = 360; # 06h00 local time
101 alt-speed-time-end = 1260; # 21h00 local time
103 ratio-limit-enabled = true;
106 rpc-bind-address = "127.0.0.1";
108 rpc-whitelist = "127.0.0.1,${wg-intra-hosts.${hostName}.ipv4}/24";
109 rpc-whitelist-enabled = true;
110 rpc-host-whitelist = "localhost,${hostName}.wg";
111 rpc-host-whitelist-enabled = true;
112 rpc-authentication-required = true;