1 { options, config, pkgs, lib, ... }:
4 inherit (lib) mkOption types mkIf;
6 opt = options.services.quicktun;
7 cfg = config.services.quicktun;
11 services.quicktun = mkOption {
16 See <http://wiki.ucis.nl/QuickTun> for more information about available options.
18 type = types.attrsOf (types.submodule ({ name, ... }: let
23 type = with types; coercedTo bool (b: if b then 1 else 0) (ints.between 0 1);
26 description = "Whether to operate in tun (IP) or tap (Ethernet) mode.";
29 remoteAddress = mkOption {
32 example = "tunnel.example.com";
34 IP address or hostname of the remote end (use `0.0.0.0` for a floating/dynamic remote endpoint).
38 localAddress = mkOption {
39 type = with types; nullOr str;
42 description = "IP address or hostname of the local end.";
45 localPort = mkOption {
48 description = "Local UDP port.";
51 remotePort = mkOption {
53 default = qtcfg.localPort;
54 defaultText = lib.literalExpression "config.services.quicktun.<name>.localPort";
55 description = " remote UDP port";
58 remoteFloat = mkOption {
59 type = with types; coercedTo bool (b: if b then 1 else 0) (ints.between 0 1);
63 Whether to allow the remote address and port to change when properly encrypted packets are received.
68 type = types.enum [ "raw" "nacl0" "nacltai" "salty" ];
70 description = "Which protocol to use.";
73 privateKey = mkOption {
74 type = with types; nullOr str;
77 Local secret key in hexadecimal form.
80 This option is deprecated. Please use {var}`services.quicktun.<name>.privateKeyFile` instead.
84 Not needed when {var}`services.quicktun.<name>.protocol` is set to `raw`.
89 privateKeyFile = mkOption {
90 type = with types; nullOr path;
91 # This is a hack to deprecate `privateKey` without using `mkChangedModuleOption`
92 default = if qtcfg.privateKey == null then null else pkgs.writeText "quickttun-key-${name}" qtcfg.privateKey;
95 Path to file containing local secret key in binary or hexadecimal form.
98 Not needed when {var}`services.quicktun.<name>.protocol` is set to `raw`.
103 publicKey = mkOption {
104 type = with types; nullOr str;
107 Remote public key in hexadecimal form.
110 Not needed when {var}`services.quicktun.<name>.protocol` is set to `raw`.
115 timeWindow = mkOption {
116 type = types.ints.unsigned;
119 Allowed time window for first received packet in seconds (positive number allows packets from history)
123 upScript = mkOption {
124 type = with types; nullOr lines;
127 Run specified command or script after the tunnel device has been opened.
136 warnings = lib.pipe cfg [
137 (lib.mapAttrsToList (name: value: if value.privateKey != null then name else null))
138 (builtins.filter (n: n != null))
139 (map (n: " - services.quicktun.${n}.privateKey"))
140 (services: lib.optional (services != [ ]) ''
141 `services.quicktun.<name>.privateKey` is deprecated.
142 Please use `services.quicktun.<name>.privateKeyFile` instead.
145 ${lib.concatStringsSep "\n" services}
149 systemd.services = lib.mkMerge (
150 lib.mapAttrsToList (name: qtcfg: {
151 "quicktun-${name}" = {
152 wantedBy = [ "multi-user.target" ];
153 after = [ "network.target" ];
156 TUN_MODE = toString qtcfg.tunMode;
157 REMOTE_ADDRESS = qtcfg.remoteAddress;
158 LOCAL_ADDRESS = mkIf (qtcfg.localAddress != null) (qtcfg.localAddress);
159 LOCAL_PORT = toString qtcfg.localPort;
160 REMOTE_PORT = toString qtcfg.remotePort;
161 REMOTE_FLOAT = toString qtcfg.remoteFloat;
162 PRIVATE_KEY_FILE = mkIf (qtcfg.privateKeyFile != null) qtcfg.privateKeyFile;
163 PUBLIC_KEY = mkIf (qtcfg.publicKey != null) qtcfg.publicKey;
164 TIME_WINDOW = toString qtcfg.timeWindow;
165 TUN_UP_SCRIPT = mkIf (qtcfg.upScript != null) (pkgs.writeScript "quicktun-${name}-up.sh" qtcfg.upScript);
170 ExecStart = "${pkgs.quicktun}/bin/quicktun.${qtcfg.protocol}";