1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let cfg = config.services.gogoclient;
6in
7
8{
9
10 ###### interface
11
12 options = {
13 services.gogoclient = {
14 enable = mkOption {
15 default = false;
16 type = types.bool;
17 description = ''
18 Enable the gogoCLIENT IPv6 tunnel.
19 '';
20 };
21 autorun = mkOption {
22 default = true;
23 description = ''
24 Whether to automatically start the tunnel.
25 '';
26 };
27
28 username = mkOption {
29 default = "";
30 description = ''
31 Your Gateway6 login name, if any.
32 '';
33 };
34
35 password = mkOption {
36 default = "";
37 type = types.string;
38 description = ''
39 Path to a file (as a string), containing your gogoNET password, if any.
40 '';
41 };
42
43 server = mkOption {
44 default = "anonymous.freenet6.net";
45 example = "broker.freenet6.net";
46 description = "The Gateway6 server to be used.";
47 };
48 };
49 };
50
51 ###### implementation
52
53 config = mkIf cfg.enable {
54 boot.kernelModules = [ "tun" ];
55
56 networking.enableIPv6 = true;
57
58 systemd.services.gogoclient = {
59 description = "ipv6 tunnel";
60
61 after = [ "network.target" ];
62 requires = [ "network.target" ];
63
64 unitConfig.RequiresMountsFor = "/var/lib/gogoc";
65
66 script = let authMethod = if cfg.password == "" then "anonymous" else "any"; in ''
67 mkdir -p -m 700 /var/lib/gogoc
68 cat ${pkgs.gogoclient}/share/${pkgs.gogoclient.name}/gogoc.conf.sample | \
69 ${pkgs.gnused}/bin/sed \
70 -e "s|^userid=|&${cfg.username}|" \
71 -e "s|^passwd=|&${optionalString (cfg.password != "") "$(cat ${cfg.password})"}|" \
72 -e "s|^server=.*|server=${cfg.server}|" \
73 -e "s|^auth_method=.*|auth_method=${authMethod}|" \
74 -e "s|^#log_file=|log_file=1|" > /var/lib/gogoc/gogoc.conf
75 cd /var/lib/gogoc
76 exec ${pkgs.gogoclient}/bin/gogoc -y -f /var/lib/gogoc/gogoc.conf
77 '';
78 } // optionalAttrs cfg.autorun {
79 wantedBy = [ "multi-user.target" ];
80 };
81
82 };
83
84}