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