forked from
lass.pds.lassul.us/superconfig
This repository has no description
2.6 kB
84 lines
1{
2 _class = "clan.service";
3 manifest.name = "tor";
4 manifest.description = "tor networking between hosts";
5 manifest.categories = [ "networking" ];
6 roles.default = {
7 # interface =
8 # { lib, ... }:
9 # {
10 # options = {
11 # OciSettings = lib.mkOption {
12 # type = lib.types.raw;
13 # default = null;
14 # description = "NixOS settings for virtualisation.oci-container.<name>.settings";
15 # };
16 # buildContainer = lib.mkOption {
17 # type = lib.types.nullOr lib.types.str;
18 # default = null;
19 # };
20 # };
21 # };
22 perInstance =
23 {
24 instanceName,
25 roles,
26 lib,
27 ...
28 }:
29 {
30 # nix run .#clan.inventory.instances.<instanceName>.actions.build-docker-container
31 exports.networking = {
32 priority = lib.mkDefault 10;
33 # TODO add user space network support to clan-cli
34 technology = "tor";
35 peers = lib.mapAttrs (name: _machine: {
36 host.var = {
37 machine = name;
38 generator = "tor-ssh";
39 file = "hostname";
40 };
41 }) roles.default.machines;
42 };
43 nixosModule =
44 {
45 pkgs,
46 config,
47 ...
48 }:
49 {
50 config = {
51 services.tor = {
52 enable = true;
53 relay.onionServices."clan_${instanceName}" = {
54 version = 3;
55 # TODO get ports from instance machine config
56 map = [
57 {
58 port = 22;
59 target.port = 22;
60 }
61 ];
62 secretKey = config.clan.core.vars.generators."tor_${instanceName}".files.hs_ed25519_secret_key.path;
63 };
64 };
65 clan.core.vars.generators."tor_${instanceName}" = {
66 files.hs_ed25519_secret_key = { };
67 files.hostname = { };
68 runtimeInputs = with pkgs; [
69 coreutils
70 tor
71 ];
72 script = ''
73 mkdir -p data
74 echo -e "DataDirectory ./data\nSocksPort 0\nHiddenServiceDir ./hs\nHiddenServicePort 80 127.0.0.1:80" > torrc
75 timeout 2 tor -f torrc || :
76 mv hs/hs_ed25519_secret_key $out/hs_ed25519_secret_key
77 mv hs/hostname $out/hostname
78 '';
79 };
80 };
81 };
82 };
83 };
84}