1{
2 config,
3 lib,
4 pkgs,
5 ...
6}:
7
8with lib;
9
10let
11 cfg = config.services.miredo;
12 pidFile = "/run/miredo.pid";
13 miredoConf = pkgs.writeText "miredo.conf" ''
14 InterfaceName ${cfg.interfaceName}
15 ServerAddress ${cfg.serverAddress}
16 ${optionalString (cfg.bindAddress != null) "BindAddress ${cfg.bindAddress}"}
17 ${optionalString (cfg.bindPort != null) "BindPort ${cfg.bindPort}"}
18 '';
19in
20{
21
22 ###### interface
23
24 options = {
25
26 services.miredo = {
27
28 enable = mkEnableOption "the Miredo IPv6 tunneling service";
29
30 package = mkPackageOption pkgs "miredo" { };
31
32 serverAddress = mkOption {
33 default = "teredo.remlab.net";
34 type = types.str;
35 description = ''
36 The hostname or primary IPv4 address of the Teredo server.
37 This setting is required if Miredo runs as a Teredo client.
38 "teredo.remlab.net" is an experimental service for testing only.
39 Please use another server for production and/or large scale deployments.
40 '';
41 };
42
43 interfaceName = mkOption {
44 default = "teredo";
45 type = types.str;
46 description = ''
47 Name of the network tunneling interface.
48 '';
49 };
50
51 bindAddress = mkOption {
52 default = null;
53 type = types.nullOr types.str;
54 description = ''
55 Depending on the local firewall/NAT rules, you might need to force
56 Miredo to use a fixed UDP port and or IPv4 address.
57 '';
58 };
59
60 bindPort = mkOption {
61 default = null;
62 type = types.nullOr types.str;
63 description = ''
64 Depending on the local firewall/NAT rules, you might need to force
65 Miredo to use a fixed UDP port and or IPv4 address.
66 '';
67 };
68 };
69 };
70
71 ###### implementation
72
73 config = mkIf cfg.enable {
74
75 systemd.services.miredo = {
76 wantedBy = [ "multi-user.target" ];
77 after = [ "network.target" ];
78 description = "Teredo IPv6 Tunneling Daemon";
79 serviceConfig = {
80 Restart = "always";
81 RestartSec = "5s";
82 ExecStart = "${cfg.package}/bin/miredo -c ${miredoConf} -p ${pidFile} -f";
83 ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
84 };
85 };
86
87 };
88
89}