summaryrefslogtreecommitdiff
path: root/os/srv/i2p.nix
blob: 5e36c206f696d3c9106f0fb1f1ee6ba0b5172c54 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
{
  config,
  lib,
  masterDomain,
  securityTemplates,
  ...
}:
let
  cfg = config.os.srv.i2p;
in
{
  options.os.srv.i2p = {
    enable = lib.mkEnableOption "enables a flexible, polymorphic i2pd deployment profile";

    mode = lib.mkOption {
      type = lib.types.enum [
        "server"
        "client"
      ];
      default = "client";
      description = "";
    };
  };

  config = lib.mkIf cfg.enable (
    lib.mkMerge [
      {
        services.i2pd = {
          enable = true;
          enableIPv6 = true;
          reseed.verify = true;

          yggdrasil.enable = true;

          proto = {
            http.enable = true;
            httpProxy.enable = true;
            socksProxy = {
              enable = true;
              outproxyEnable = true;
            };
            sam.enable = true;
            i2pControl.enable = true;
          };
        };
      }

      (lib.mkIf (cfg.mode == "server") {
        services.i2pd = {
          bandwidth = 4096;

          ntcp2.published = true;
          ssu2.published = true;

          #TODO add address
          yggdrasil.address = "";
        };

        os.cluster.nginxProxies."i2p.${masterDomain}" = {
          enableACME = true;
          forceSSL = true;
          locations."/" = {
            proxyPass = "http://${config.os.core.network.ips.relay-vm}:7070";
            extraConfig = securityTemplates.restrictToInternal;
          };
        };
      })

      (lib.mkIf (cfg.mode == "client") {
        services.i2pd = {
          bandwidth = 512;

          ntcp2.published = false;
          ssu2.published = false;

          yggdrasil.address = "";
        };
      })
    ]
  );
}