1 { pkgs, lib, config, ... }:
3 inherit (config) networking;
4 inherit (config.services) tor;
5 inherit (config.users) users;
6 inherit (config.security) gnupg;
7 ports = lib.flatten (map (map (p: p.port)) [tor.settings.ORPort tor.settings.DirPort]);
8 onion = "5spcvlzbaxwo4knhwnrekjtnakxmvekmlc5qwsigi33rn45hd5gewlyd";
11 environment.systemPackages = [
12 #pkgs.pythonPackages.stem
15 networking.nftables.ruleset = ''
16 add rule inet filter fw2net meta skuid ${users.tor.name} meta l4proto tcp counter accept comment "Tor"
17 '' + lib.optionalString (ports != []) ''
18 add rule inet filter net2fw tcp dport {${lib.concatMapStringsSep "," toString ports}} counter accept comment "Tor"
20 #security.gnupg.secrets."tor/auth/julm" = {};
21 security.gnupg.secrets."tor/onion/${onion}/hs_ed25519_secret_key" = {
22 systemdConfig.before = [ "tor.service" ];
23 systemdConfig.requiredBy = [ "tor.service" ];
28 controlSocket.enable = true;
31 relay.role = "private-bridge";
32 #client.privoxy.enable = false;
33 relay.onionServices = {
34 "ssh/${networking.domain}/${networking.hostName}" = {
35 secretKey = gnupg.secrets."tor/onion/${onion}/hs_ed25519_secret_key".path;
39 "descriptor:x25519:2EZQ3AOZXERDVSN6WO5LNSCOIIPL2AT2A7KOS4ZIYNVQDR5EFM2Q" # julm
43 #HiddenServiceNumIntroductionPoints = 20;
48 #{ addr = "[::]"; port = 2222; NoAdvertise = false; IPv6Only = true; }
49 { port = 2222; IPv4Only = false; }
50 #{ addr = "80.67.180.251"; port = 222; IPv4Only = true; NoAdvertise = true; }
52 settings.BandwidthRate = 500000;
53 settings.ReducedExitPolicy = true;
54 settings.ExitPolicy = [
56 "reject 185.30.166.38"
57 "reject 185.30.166.37"
59 "reject 130.185.232.126"
60 "reject 185.191.225.10"
61 "reject [2a01:7e00::f03c:91ff:fee2:413b]"
62 "reject [2001:6b0:e:2a18::119]"
63 "reject [2600:3c02::f03c:91ff:fe59:7d2e]"
66 settings.TransPort = { port = 9040; };
67 settings.DNSPort = { port = 9053; };
68 #settings.ExtORPort = lib.mkForce null;
69 settings.AutomapHostsOnResolve = true;
73 boot.initrd.secrets = {
74 "/var/lib/tor/onion/ssh/hs_ed25519_secret_key" =
75 gnupg.secrets."tor/onion/${onion}/hs_ed25519_secret_key".path;
77 boot.initrd.extraUtilsCommands = ''
78 copy_bin_and_libs ${pkgs.tor}/bin/tor
80 boot.initrd.network.postCommands = let
81 torRc = pkgs.writeText "tor.rc" ''
82 DataDirectory /var/lib/tor
83 HiddenServicePort 22 127.0.0.1:2222
84 HiddenServiceDir /var/lib/tor/onion/ssh
87 echo "tor: preparing onion folder"
88 # have to do this otherwise tor does not want to start
89 install -d -m 700 /var/lib/tor
91 echo "make sure localhost is up"
92 ip addr add 127.0.0.1/8 dev lo
95 echo "tor: starting tor"
96 tor -f ${torRc} --verify-config