{ pkgs, lib, config, ... }: let inherit (config) networking; inherit (config.services) tor; inherit (config.users) users; inherit (config.security) gnupg; ports = lib.flatten (map (map (p: p.port)) [tor.settings.ORPort tor.settings.DirPort]); in { environment.systemPackages = [ #pkgs.pythonPackages.stem pkgs.nyx ]; networking.nftables.ruleset = '' add rule inet filter net2fw tcp dport {${lib.concatMapStringsSep "," toString ports}} counter accept comment "Tor" add rule inet filter fw2net meta skuid ${users.tor.name} meta l4proto tcp counter accept comment "Tor" ''; systemd.services.tor-init.script = '' install -d -m 700 -o tor -g tor /var/lib/tor/onion/${networking.domain} ''; systemd.services.tor.serviceConfig.StateDirectoryMode = "0700"; #security.gnupg.secrets."tor/auth/julm" = {}; services.tor = { enable = true; #enableGeoIP = false; controlSocket.enable = true; #controlPort = [9051]; relay.enable = true; relay.role = "private-bridge"; client.enable = true; client.privoxy.enable = true; /* hiddenServices = { "${networking.domain}/${networking.hostName}" = { version = 3; map = [ { port = 22; target = { addr = "127.0.0.1"; port = 22; }; } ]; settings = { #HiddenServiceNumIntroductionPoints = 20; }; }; }; */ settings.ORPort = [ #{ addr = "[::]"; port = 2222; NoAdvertise = false; IPv6Only = true; } { port = 2222; NoAdvertise = false; IPv4Only = false; } #{ addr = "80.67.180.251"; port = 222; IPv4Only = true; NoAdvertise = true; } ]; settings.BandwidthRate = 500000; settings.ReducedExitPolicy = true; settings.ExitPolicy = [ # irc.freenode.net "reject 185.30.166.38" "reject 185.30.166.37" "reject 38.229.70.22" "reject 130.185.232.126" "reject 185.191.225.10" "reject [2a01:7e00::f03c:91ff:fee2:413b]" "reject [2001:6b0:e:2a18::119]" "reject [2600:3c02::f03c:91ff:fe59:7d2e]" ]; settings.TransPort = { port = 9040; }; settings.DNSPort = { port = 9053; }; #settings.ExtORPort = lib.mkForce null; settings.AutomapHostsOnResolve = true; }; /* # copy your onion folder boot.initrd.secrets = { "/etc/tor/onion/bootup" = /home/tony/tor/onion; # maybe find a better spot to store this. }; # copy tor to you initrd boot.initrd.extraUtilsCommands = '' copy_bin_and_libs ${pkgs.tor}/bin/tor ''; # start tor during boot process boot.initrd.network.postCommands = let torRc = (pkgs.writeText "tor.rc" '' DataDirectory /etc/tor SOCKSPort 127.0.0.1:9050 IsolateDestAddr SOCKSPort 127.0.0.1:9063 HiddenServiceDir /etc/tor/onion/bootup HiddenServicePort 22 127.0.0.1:22 ''); in '' echo "tor: preparing onion folder" # have to do this otherwise tor does not want to start chmod -R 700 /etc/tor echo "make sure localhost is up" ip a a 127.0.0.1/8 dev lo ip link set lo up echo "tor: starting tor" tor -f ${torRc} --verify-config tor -f ${torRc} & ''; */ }