]> Git — Sourcephile - sourcephile-nix.git/blob - hosts/losurdo/networking/tor.nix
losurdo: openvpn: switch to calyx while riseup is down
[sourcephile-nix.git] / hosts / losurdo / networking / tor.nix
1 { pkgs, lib, config, ... }:
2 let
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";
9 in
10 {
11 environment.systemPackages = [
12 #pkgs.pythonPackages.stem
13 pkgs.nyx
14 ];
15 networking.nftables.ruleset = lib.optionalString (ports != []) ''
16 table inet filter {
17 chain input-net {
18 tcp dport {${lib.concatMapStringsSep "," toString ports}} counter accept comment "tor"
19 }
20 }
21 '' + ''
22 table inet filter {
23 chain output-net {
24 skuid ${users.tor.name} tcp counter accept comment "tor"
25 }
26 }
27 '';
28 #security.gnupg.secrets."tor/auth/julm" = {};
29 security.gnupg.secrets."tor/onion/${onion}/hs_ed25519_secret_key" = {
30 systemdConfig.before = [ "tor.service" ];
31 systemdConfig.requiredBy = [ "tor.service" ];
32 };
33 services.tor = {
34 enable = true;
35 enableGeoIP = true;
36 controlSocket.enable = true;
37 client.enable = true;
38 client.dns.enable = true;
39 relay.enable = false;
40 relay.role = "private-bridge";
41 #client.privoxy.enable = false;
42 relay.onionServices = {
43 "ssh/${networking.domain}/${networking.hostName}" = {
44 secretKey = gnupg.secrets."tor/onion/${onion}/hs_ed25519_secret_key".path;
45 map = [ 22 ];
46 /*
47 authorizedClients = [
48 "descriptor:x25519:2EZQ3AOZXERDVSN6WO5LNSCOIIPL2AT2A7KOS4ZIYNVQDR5EFM2Q" # julm
49 ];
50 */
51 settings = {
52 #HiddenServiceNumIntroductionPoints = 20;
53 };
54 };
55 };
56 settings.AutomapHostsSuffixes = [".onion"];
57 settings.ORPort = [
58 #{ addr = "[::]"; port = 2222; NoAdvertise = false; IPv6Only = true; }
59 { port = 2222; IPv4Only = false; }
60 #{ addr = "80.67.180.251"; port = 222; IPv4Only = true; NoAdvertise = true; }
61 ];
62 settings.BandwidthRate = 500000;
63 settings.ReducedExitPolicy = true;
64 settings.ExitPolicy = [
65 # irc.freenode.net
66 "reject 185.30.166.38"
67 "reject 185.30.166.37"
68 "reject 38.229.70.22"
69 "reject 130.185.232.126"
70 "reject 185.191.225.10"
71 "reject [2a01:7e00::f03c:91ff:fee2:413b]"
72 "reject [2001:6b0:e:2a18::119]"
73 "reject [2600:3c02::f03c:91ff:fe59:7d2e]"
74 ];
75 /*
76 settings.TransPort = { port = 9040; };
77 settings.DNSPort = { port = 9053; };
78 #settings.ExtORPort = lib.mkForce null;
79 settings.AutomapHostsOnResolve = true;
80 */
81 };
82 /*
83 boot.initrd.secrets = {
84 "/var/lib/tor/onion/ssh/hs_ed25519_secret_key" =
85 gnupg.secrets."tor/onion/${onion}/hs_ed25519_secret_key".path;
86 };
87 boot.initrd.extraUtilsCommands = ''
88 copy_bin_and_libs ${pkgs.tor}/bin/tor
89 '';
90 boot.initrd.network.postCommands = let
91 torRc = pkgs.writeText "tor.rc" ''
92 DataDirectory /var/lib/tor
93 HiddenServicePort 22 127.0.0.1:2222
94 HiddenServiceDir /var/lib/tor/onion/ssh
95 '';
96 in ''
97 echo "tor: preparing onion folder"
98 # have to do this otherwise tor does not want to start
99 install -d -m 700 /var/lib/tor
100
101 echo "make sure localhost is up"
102 ip addr add 127.0.0.1/8 dev lo
103 ip link set lo up
104
105 echo "tor: starting tor"
106 tor -f ${torRc} --verify-config
107 tor -f ${torRc} &
108 '';
109 */
110 }