summary refs log tree commit diff
path: root/nixos/modules/services/networking/aiccu.nix
blob: aeb0910d62468d3a6c1caa623e38740f2244046b (plain) (blame)
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
{ config, lib, pkgs, ... }:

with lib;

let

  cfg = config.services.aiccu;
  showBool = b: if b then "true" else "false";
  notNull = a: ! isNull a;
  configFile = pkgs.writeText "aiccu.conf" ''
    ${if notNull cfg.username then "username " + cfg.username else ""}
    ${if notNull cfg.password then "password " + cfg.password else ""}
    protocol ${cfg.protocol}
    server ${cfg.server}
    ipv6_interface ${cfg.interfaceName}
    verbose ${showBool cfg.verbose}
    daemonize true
    automatic ${showBool cfg.automatic}
    requiretls ${showBool cfg.requireTLS}
    pidfile ${cfg.pidFile}
    defaultroute ${showBool cfg.defaultRoute}
    ${if notNull cfg.setupScript then cfg.setupScript else ""}
    makebeats ${showBool cfg.makeHeartBeats}
    noconfigure ${showBool cfg.noConfigure}
    behindnat ${showBool cfg.behindNAT}
    ${if cfg.localIPv4Override then "local_ipv4_override" else ""}
  '';

in {

  options = {

    services.aiccu = {

      enable = mkOption {
        type = types.bool;
        default = false;
        description = "Enable aiccu IPv6 over IPv4 SiXXs tunnel";
      };

      username = mkOption {
        type = with types; nullOr str;
        default = null;
        example = "FAB5-SIXXS";
        description = "Login credential";
      };

      password = mkOption {
        type = with types; nullOr str;
        default = null;
        example = "TmAkRbBEr0";
        description = "Login credential";
      };

      protocol = mkOption {
        type = types.str;
        default = "tic";
        example = "tic|tsp|l2tp";
        description = "Protocol to use for setting up the tunnel";
      };

      server = mkOption {
        type = types.str;
        default = "tic.sixxs.net";
        example = "enabled.ipv6server.net";
        description = "Server to use for setting up the tunnel";
      };

      interfaceName = mkOption {
        type = types.str;
        default = "aiccu";
        example = "sixxs";
        description = ''
          The name of the interface that will be used as a tunnel interface.
          On *BSD the ipv6_interface should be set to gifX (eg gif0) for proto-41 tunnels
          or tunX (eg tun0) for AYIYA tunnels.
        '';
      };

      tunnelID = mkOption {
        type = with types; nullOr str;
        default = null;
        example = "T12345";
        description = "The tunnel id to use, only required when there are multiple tunnels in the list";
      };

      verbose = mkOption {
        type = types.bool;
        default = false;
        description = "Be verbose?";
      };

      automatic = mkOption {
        type = types.bool;
        default = true;
        description = "Automatic Login and Tunnel activation";
      };

      requireTLS = mkOption {
        type = types.bool;
        default = false;
        description = ''
          When set to true, if TLS is not supported on the server
          the TIC transaction will fail.
          When set to false, it will try a starttls, when that is
          not supported it will continue.
          In any case if AICCU is build with TLS support it will
          try to do a 'starttls' to the TIC server to see if that
          is supported.
        '';
      };

      pidFile = mkOption {
        type = types.path;
        default = "/run/aiccu.pid";
        example = "/var/lib/aiccu/aiccu.pid";
        description = "Location of PID File";
      };

      defaultRoute = mkOption {
        type = types.bool;
        default = true;
        description = "Add a default route";
      };

      setupScript = mkOption {
        type = with types; nullOr path;
        default = null;
        example = "/var/lib/aiccu/fix-subnets.sh";
        description = "Script to run after setting up the interfaces";
      };

      makeHeartBeats = mkOption {
        type = types.bool;
        default = true;
        description = ''
          In general you don't want to turn this off
          Of course only applies to AYIYA and heartbeat tunnels not to static ones
        '';
      };

      noConfigure = mkOption {
        type = types.bool;
        default = false;
        description = "Don't configure anything";
      };

      behindNAT = mkOption {
        type = types.bool;
        default = false;
        description = "Notify the user that a NAT-kind network is detected";
      };

      localIPv4Override = mkOption {
        type = types.bool;
        default = false;
        description = ''
          Overrides the IPv4 parameter received from TIC
          This allows one to configure a NAT into "DMZ" mode and then
          forwarding the proto-41 packets to an internal host.

          This is only needed for static proto-41 tunnels!
          AYIYA and heartbeat tunnels don't require this.
        '';
      };

    };
  };

  config = mkIf cfg.enable {

    systemd.services.aiccu = {
      description = "Automatic IPv6 Connectivity Client Utility";
      after = [ "network.target" ];
      wantedBy = [ "multi-user.target" ];
      serviceConfig = {
        ExecStart = "${pkgs.aiccu}/bin/aiccu start ${configFile}";
        ExecStop = "${pkgs.aiccu}/bin/aiccu stop";
        Type = "forking";
        PIDFile = cfg.pidFile;
        Restart = "no"; # aiccu startup errors are serious, do not pound the tic server or be banned.
      };
    };

  };
}