This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

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