nixpkgs/nixos/modules/services/networking/quicktun.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

119 lines
2.9 KiB
Nix
Raw Normal View History

2019-04-02 10:15:12 +00:00
{ config, pkgs, lib, ... }:
let
cfg = config.services.quicktun;
in
with lib;
{
options = {
services.quicktun = mkOption {
default = { };
description = lib.mdDoc "QuickTun tunnels";
2019-04-02 10:15:12 +00:00
type = types.attrsOf (types.submodule {
options = {
tunMode = mkOption {
type = types.int;
default = 0;
example = 1;
description = lib.mdDoc "";
2019-04-02 10:15:12 +00:00
};
remoteAddress = mkOption {
type = types.str;
example = "tunnel.example.com";
description = lib.mdDoc "";
2019-04-02 10:15:12 +00:00
};
localAddress = mkOption {
type = types.str;
example = "0.0.0.0";
description = lib.mdDoc "";
2019-04-02 10:15:12 +00:00
};
localPort = mkOption {
type = types.int;
default = 2998;
description = lib.mdDoc "";
2019-04-02 10:15:12 +00:00
};
remotePort = mkOption {
type = types.int;
default = 2998;
description = lib.mdDoc "";
2019-04-02 10:15:12 +00:00
};
remoteFloat = mkOption {
type = types.int;
default = 0;
description = lib.mdDoc "";
2019-04-02 10:15:12 +00:00
};
protocol = mkOption {
type = types.str;
default = "nacltai";
description = lib.mdDoc "";
2019-04-02 10:15:12 +00:00
};
privateKey = mkOption {
type = types.str;
description = lib.mdDoc "";
2019-04-02 10:15:12 +00:00
};
publicKey = mkOption {
type = types.str;
description = lib.mdDoc "";
2019-04-02 10:15:12 +00:00
};
timeWindow = mkOption {
type = types.int;
default = 5;
description = lib.mdDoc "";
2019-04-02 10:15:12 +00:00
};
upScript = mkOption {
type = types.lines;
default = "";
description = lib.mdDoc "";
2019-04-02 10:15:12 +00:00
};
};
});
};
};
config = mkIf (cfg != []) {
2021-01-25 06:57:48 +00:00
systemd.services = foldr (a: b: a // b) {} (
2019-04-02 10:15:12 +00:00
mapAttrsToList (name: qtcfg: {
"quicktun-${name}" = {
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
environment = {
2019-08-13 21:52:01 +00:00
INTERFACE = name;
TUN_MODE = toString qtcfg.tunMode;
REMOTE_ADDRESS = qtcfg.remoteAddress;
LOCAL_ADDRESS = qtcfg.localAddress;
LOCAL_PORT = toString qtcfg.localPort;
REMOTE_PORT = toString qtcfg.remotePort;
REMOTE_FLOAT = toString qtcfg.remoteFloat;
PRIVATE_KEY = qtcfg.privateKey;
PUBLIC_KEY = qtcfg.publicKey;
TIME_WINDOW = toString qtcfg.timeWindow;
TUN_UP_SCRIPT = pkgs.writeScript "quicktun-${name}-up.sh" qtcfg.upScript;
SUID = "nobody";
2019-04-02 10:15:12 +00:00
};
serviceConfig = {
Type = "simple";
ExecStart = "${pkgs.quicktun}/bin/quicktun.${qtcfg.protocol}";
};
};
}) cfg
);
};
}