This repository has no description
5.0 kB
152 lines
1{
2 config,
3 pkgs,
4 lib,
5 ...
6}:
7let
8 torrentport = 56709; # port forwarded in airvpn webinterface
9in
10{
11 clan.core.vars.password-store.secretLocation = "/var/state/secret-vars";
12
13 imports = [
14 ../../configs
15 ../../configs/retiolum.nix
16 ../../configs/services/flix
17 ../../configs/autoupdate.nix
18 ../../configs/services/archiver-bot.nix
19 ];
20
21 # we need to configure another port for the mycelium admin interface, because it conflicts with sonarr.
22 services.mycelium.extraArgs = [
23 "--api-addr"
24 "127.0.0.1:9898"
25 ];
26
27 services.transmission.settings.peer-port = torrentport;
28
29 krebs.sync-containers3.inContainer = {
30 enable = true;
31 pubkey = builtins.readFile ./facts/yellow.sync.pub;
32 };
33
34 networking.useHostResolvConf = false;
35 networking.useNetworkd = true;
36 networking.resolvconf.enable = false;
37 # we need to set a namserver here that can be also be reached from the transmission network namespace
38 environment.etc."resolv.conf".text = ''
39 options edns0
40 nameserver 1.1.1.1
41 '';
42 services.resolved.enable = lib.mkForce false;
43
44 systemd.services."netns@" = {
45 description = "%I network namespace";
46 before = [ "network.target" ];
47 serviceConfig = {
48 Type = "oneshot";
49 RemainAfterExit = true;
50 ExecStart = "${pkgs.iproute2}/bin/ip netns add %I";
51 ExecStop = "${pkgs.iproute2}/bin/ip netns del %I";
52 };
53 };
54
55 systemd.services.transmission-netns = {
56 bindsTo = [ "netns@transmission.service" ];
57 after = [ "netns@transmission.service" ];
58 path = [
59 pkgs.iproute2
60 pkgs.wireguard-tools
61 pkgs.gnused
62 pkgs.gawk
63 ];
64 script = ''
65 set -efux
66 until ${pkgs.dig.host}/bin/host europe.vpn.airdns.org; do sleep 1; done
67
68 ip link del t2 || :
69 ip -n transmission link set lo up
70 ip link add airvpn type wireguard
71 ip -n transmission link del airvpn || :
72 ip link set airvpn netns transmission
73 ip -n transmission addr add 10.176.43.231/32 dev airvpn
74 ip -n transmission addr add fd7d:76ee:e68f:a993:41b3:846b:d271:30d8/128 dev airvpn
75 # The transmission netns has no route until the tunnel is up, so wg must
76 # not resolve the endpoint from inside it: recent wireguard-tools resolve
77 # in the current netns, which stalls the deploy on ~70s of DNS retries.
78 # Resolve here in the main netns and hand wg a numeric Endpoint.
79 conf=$(wg-quick strip ${config.clan.core.vars.generators.airvpn.files."airvpn.conf".path})
80 ep=$(printf '%s\n' "$conf" | sed -n 's/^Endpoint *= *//p')
81 ephost=''${ep%:*}
82 epport=''${ep##*:}
83 epip=$(${pkgs.dig.host}/bin/host "$ephost" | awk '/has address/ { print $NF; exit }')
84 ip netns exec transmission wg syncconf airvpn \
85 <(printf '%s\n' "$conf" | sed "s|$ephost:$epport|$epip:$epport|")
86 ip -n transmission link set airvpn up
87 ip -n transmission route add default dev airvpn
88 ip -6 -n transmission route add default dev airvpn
89 ip link add t1 type veth peer name t2
90
91 ip -n transmission link del t1 || :
92 ip link set t1 netns transmission
93
94 ip addr add 128.0.0.2/30 dev t2
95 ip addr add fdb4:3310:947::1/64 dev t2
96 ip link set t2 up
97 ip -n transmission addr add 128.0.0.1/30 dev t1
98 ip -n transmission addr add fdb4:3310:947::2/64 dev t1
99 ip -n transmission link set t1 up
100 ip -n transmission route add 42:0:ce16::3110/16 via fdb4:3310:947::1 dev t1
101 '';
102 serviceConfig = {
103 RemainAfterExit = true;
104 Type = "oneshot";
105 };
106 };
107
108 clan.core.vars.generators.airvpn = {
109 files."airvpn.conf" = { };
110 prompts.config.description = ''
111 login into https://airvpn.org/ goto https://airvpn.org/generator/
112 generate a wireguard config
113 paste the config here
114 '';
115 runtimeInputs = with pkgs; [ coreutils ];
116 script = ''
117 cat "$prompts"/config > "$out"/airvpn.conf
118 '';
119 };
120
121 # so we can forward traffic from the transmission network namespace
122 boot.kernel.sysctl."net.ipv6.conf.all.forwarding" = 1;
123
124 systemd.services.transmission = {
125 after = [ "transmission-netns.service" ];
126 wants = [ "transmission-netns.service" ];
127 bindsTo = [ "netns@transmission.service" ];
128 serviceConfig = {
129 NetworkNamespacePath = "/var/run/netns/transmission";
130 # https://github.com/NixOS/nixpkgs/issues/258793
131 RootDirectoryStartOnly = lib.mkForce false;
132 RootDirectory = lib.mkForce "";
133 CPUSchedulingPolicy = "idle";
134 IOSchedulingClass = "idle";
135 IOSchedulingPriority = 7;
136 # increase file descriptor limit to handle many torrents/peers
137 LimitNOFILE = 65536;
138 };
139 };
140 clan.core.vars.generators.yellow-container = {
141 files."yellow.sync.key" = { };
142 files."yellow.sync.pub".secret = false;
143 runtimeInputs = with pkgs; [
144 coreutils
145 openssh
146 ];
147 script = ''
148 ssh-keygen -t ed25519 -N "" -f "$out"/yellow.sync.key
149 mv "$out"/yellow.sync.key.pub "$out"/yellow.sync.pub
150 '';
151 };
152}