1 { pkgs, lib, config, ... }:
2 let inherit (config) networking; in
4 environment.systemPackages = [
6 pkgs.pythonPackages.stem
10 systemd.services.tor-init.script = ''
11 install -d -m 700 -o tor -g tor /var/lib/tor/onion/${networking.domain}
14 systemd.services.tor.serviceConfig.StateDirectory = [
17 "tor/onion/${networking.domain}"
20 systemd.services.tor.serviceConfig.StateDirectoryMode = "0700";
24 controlSocket.enable = true;
26 relay.role = "private-bridge";
29 "${networking.domain}/${networking.hostName}".map = [
36 ClientPreferIPv6ORPort 0
40 # copy your onion folder
41 boot.initrd.secrets = {
42 "/etc/tor/onion/bootup" = /home/tony/tor/onion; # maybe find a better spot to store this.
45 # copy tor to you initrd
46 boot.initrd.extraUtilsCommands = ''
47 copy_bin_and_libs ${pkgs.tor}/bin/tor
50 # start tor during boot process
51 boot.initrd.network.postCommands = let
52 torRc = (pkgs.writeText "tor.rc" ''
53 DataDirectory /etc/tor
54 SOCKSPort 127.0.0.1:9050 IsolateDestAddr
55 SOCKSPort 127.0.0.1:9063
56 HiddenServiceDir /etc/tor/onion/bootup
57 HiddenServicePort 22 127.0.0.1:22
60 echo "tor: preparing onion folder"
61 # have to do this otherwise tor does not want to start
64 echo "make sure localhost is up"
65 ip a a 127.0.0.1/8 dev lo
68 echo "tor: starting tor"
69 tor -f ${torRc} --verify-config