]> Git — Sourcephile - sourcephile-nix.git/blob - machines/losurdo/networking/tor.nix
traceroute: enable for julm and root
[sourcephile-nix.git] / machines / 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 = ''
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"
19 '';
20 #security.gnupg.secrets."tor/auth/julm" = {};
21 security.gnupg.secrets."tor/onion/${onion}/hs_ed25519_secret_key" = {};
22 services.tor = {
23 enable = true;
24 enableGeoIP = true;
25 controlSocket.enable = true;
26 client.enable = true;
27 relay.enable = false;
28 relay.role = "private-bridge";
29 #client.privoxy.enable = false;
30 relay.onionServices = {
31 "ssh/${networking.domain}/${networking.hostName}" = {
32 secretKey = gnupg.secrets."tor/onion/${onion}/hs_ed25519_secret_key".path;
33 map = [ 22 ];
34 /*
35 authorizedClients = [
36 "descriptor:x25519:2EZQ3AOZXERDVSN6WO5LNSCOIIPL2AT2A7KOS4ZIYNVQDR5EFM2Q" # julm
37 ];
38 */
39 settings = {
40 #HiddenServiceNumIntroductionPoints = 20;
41 };
42 };
43 };
44 settings.ORPort = [
45 #{ addr = "[::]"; port = 2222; NoAdvertise = false; IPv6Only = true; }
46 { port = 2222; IPv4Only = false; }
47 #{ addr = "80.67.180.251"; port = 222; IPv4Only = true; NoAdvertise = true; }
48 ];
49 settings.BandwidthRate = 500000;
50 settings.ReducedExitPolicy = true;
51 settings.ExitPolicy = [
52 # irc.freenode.net
53 "reject 185.30.166.38"
54 "reject 185.30.166.37"
55 "reject 38.229.70.22"
56 "reject 130.185.232.126"
57 "reject 185.191.225.10"
58 "reject [2a01:7e00::f03c:91ff:fee2:413b]"
59 "reject [2001:6b0:e:2a18::119]"
60 "reject [2600:3c02::f03c:91ff:fe59:7d2e]"
61 ];
62 /*
63 settings.TransPort = { port = 9040; };
64 settings.DNSPort = { port = 9053; };
65 #settings.ExtORPort = lib.mkForce null;
66 settings.AutomapHostsOnResolve = true;
67 */
68 };
69
70 boot.initrd.secrets = {
71 "/var/lib/tor/onion/ssh/hs_ed25519_secret_key" =
72 gnupg.secrets."tor/onion/${onion}/hs_ed25519_secret_key".path;
73 };
74 boot.initrd.extraUtilsCommands = ''
75 copy_bin_and_libs ${pkgs.tor}/bin/tor
76 '';
77 boot.initrd.network.postCommands = let
78 torRc = pkgs.writeText "tor.rc" ''
79 DataDirectory /var/lib/tor
80 HiddenServicePort 22 127.0.0.1:2222
81 HiddenServiceDir /var/lib/tor/onion/ssh
82 '';
83 in ''
84 echo "tor: preparing onion folder"
85 # have to do this otherwise tor does not want to start
86 install -d -m 700 /var/lib/tor
87
88 echo "make sure localhost is up"
89 ip addr add 127.0.0.1/8 dev lo
90 ip link set lo up
91
92 echo "tor: starting tor"
93 tor -f ${torRc} --verify-config
94 tor -f ${torRc} &
95 '';
96 }