zerotier module: add option to join networks and open port

This commit is contained in:
obadz 2018-03-27 00:25:53 +01:00
parent decfd44b19
commit 0a9d7f0809

View File

@ -7,6 +7,16 @@ let
in
{
options.services.zerotierone.enable = mkEnableOption "ZeroTierOne";
options.services.zerotierone.joinNetworks = mkOption {
default = [];
example = [ "a8a2c3c10c1a68de" ];
type = types.listOf types.str;
description = ''
List of ZeroTier Network IDs to join on startup
'';
};
options.services.zerotierone.package = mkOption {
default = pkgs.zerotierone;
defaultText = "pkgs.zerotierone";
@ -22,12 +32,13 @@ in
path = [ cfg.package ];
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
preStart =
''
mkdir -p /var/lib/zerotier-one
preStart = ''
mkdir -p /var/lib/zerotier-one/networks.d
chmod 700 /var/lib/zerotier-one
chown -R root:root /var/lib/zerotier-one
'';
'' + (concatMapStrings (netId: ''
touch "/var/lib/zerotier-one/networks.d/${netId}.conf"
'') cfg.joinNetworks);
serviceConfig = {
ExecStart = "${cfg.package}/bin/zerotier-one";
Restart = "always";
@ -38,6 +49,9 @@ in
# ZeroTier does not issue DHCP leases, but some strangers might...
networking.dhcpcd.denyInterfaces = [ "zt0" ];
# ZeroTier receives UDP transmissions on port 9993 by default
networking.firewall.allowedUDPPorts = [ 9993 ];
environment.systemPackages = [ cfg.package ];
};
}