1 { pkgs, lib, config, inputs, hostName, ... }:
3 inherit (config.services) transmission;
4 inherit (config.users) users;
6 wg-intra-peers = import (inputs.julm-nix + "/nixos/profiles/wireguard/wg-intra/peers.nix");
9 users.groups.transmission.members = [
13 networking.nftables.ruleset = ''
16 tcp dport ${toString transmission.settings.rpc-port} \
17 counter accept comment "transmission: rpc"
21 services.netns.namespaces.${netns}.nftables = ''
24 meta l4proto { udp, tcp } \
25 th dport ${toString transmission.settings.peer-port} \
26 counter accept comment "transmission"
29 skuid ${transmission.user} counter accept comment "transmission"
33 fileSystems."/var/lib/transmission" = {
34 device = "${hostName}/var/torrents";
37 systemd.services.transmission = {
39 "netns-${netns}.service"
43 "netns-${netns}.service"
47 unitConfig.JoinsNamespaceOf = ["netns-${netns}.service"];
48 serviceConfig.BindReadOnlyPaths = ["/etc/netns/${netns}/resolv.conf:/etc/resolv.conf"];
49 serviceConfig.PrivateNetwork = true;
50 #serviceConfig.NetworkNamespacePath = "/var/run/netns/${netns}";
52 systemd.sockets.proxy-to-transmission = {
53 wantedBy = ["sockets.target"];
54 listenStreams = ["${wg-intra-peers.${hostName}.ipv4}:9091"];
55 socketConfig.FreeBind = true;
57 systemd.services.proxy-to-transmission = {
58 requires = ["transmission.service"];
59 after = ["transmission.service" "proxy-to-transmission.socket"];
60 unitConfig.JoinsNamespaceOf = ["netns-${netns}.service"];
62 ExecStart = "${pkgs.systemd}/lib/systemd/systemd-socket-proxyd 127.0.0.1:9091";
63 PrivateNetwork = true;
67 systemd.services.stop-transmission = {
68 serviceConfig.Type = "oneshot";
69 unitConfig.Conflicts = ["transmission.service"];
70 startAt = "06..19:0,15,30,45:00";
73 systemd.services.transmission.serviceConfig.LoadCredentialEncrypted =
74 [ "settings.json:${inputs.self}/hosts/${hostName}/transmission/settings.json.cred" ];
75 services.transmission = {
77 performanceNetParameters = true;
78 credentialsFile = "/run/credentials/transmission.service/settings.json";
81 download-dir = "/var/lib/transmission/downloaded";
82 incomplete-dir = "/var/lib/transmission/.incoming";
83 incomplete-dir-enabled = true;
84 watch-dir = "/var/lib/transmission/.torrents";
85 watch-dir-enabled = true;
86 trash-original-torrent-files = false;
88 umask = 7; # 007 octal, in decimal!
89 download-queue-enabled = true;
90 download-queue-size = 5;
91 peer-id-ttl-hours = 6;
92 peer-limit-global = 1000;
93 peer-limit-per-torrent = 100;
96 peer-port-random-on-start = false;
101 port-forwarding-enabled = true;
102 scrape-paused-torrents-enabled = false;
103 peer-socket-tos = "lowcost";
104 queue-stalled-enabled = true;
105 queue-stalled-minutes = 30;
106 speed-limit-down-enabled = false;
108 speed-limit-up-enabled = true;
109 alt-speed-enabled = true;
110 alt-speed-time-enabled = true;
111 alt-speed-down = 1000;
113 alt-speed-time-day = 127; # all days. 65; # weekend only
114 alt-speed-time-begin = 360; # 06h00 local time
115 alt-speed-time-end = 1260; # 21h00 local time
117 ratio-limit-enabled = true;
120 rpc-bind-address = "127.0.0.1";
122 rpc-whitelist = "127.0.0.1,${wg-intra-peers.${hostName}.ipv4}/24";
123 rpc-whitelist-enabled = true;
124 rpc-host-whitelist = "localhost,${hostName}.wg";
125 rpc-host-whitelist-enabled = true;
126 rpc-authentication-required = true;