2015-06-07 05:10:52 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.zerotierone;
|
|
|
|
in
|
|
|
|
{
|
2022-08-28 20:18:44 +01:00
|
|
|
options.services.zerotierone.enable = mkEnableOption (lib.mdDoc "ZeroTierOne");
|
2018-03-27 00:25:53 +01:00
|
|
|
|
|
|
|
options.services.zerotierone.joinNetworks = mkOption {
|
|
|
|
default = [];
|
|
|
|
example = [ "a8a2c3c10c1a68de" ];
|
|
|
|
type = types.listOf types.str;
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc ''
|
2023-08-08 10:30:12 +01:00
|
|
|
List of ZeroTier Network IDs to join on startup.
|
|
|
|
Note that networks are only ever joined, but not automatically left after removing them from the list.
|
|
|
|
To remove networks, use the ZeroTier CLI: `zerotier-cli leave <network-id>`
|
2018-03-27 00:25:53 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2018-06-24 02:07:30 +01:00
|
|
|
options.services.zerotierone.port = mkOption {
|
|
|
|
default = 9993;
|
2022-11-09 21:30:00 +00:00
|
|
|
type = types.port;
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc ''
|
2018-06-24 02:07:30 +01:00
|
|
|
Network port used by ZeroTier.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2023-11-27 00:19:27 +00:00
|
|
|
options.services.zerotierone.package = mkPackageOption pkgs "zerotierone" { };
|
2023-12-17 23:29:14 +00:00
|
|
|
|
|
|
|
options.services.zerotierone.localConf = mkOption {
|
|
|
|
default = { };
|
|
|
|
description = mdDoc ''
|
|
|
|
Configuration to be written to the zerotier JSON-based local.conf.
|
|
|
|
The configuration will be symlinked to /var/lib/zerotier-one/local.conf at build time.
|
|
|
|
To understand the configuration format, refer to https://docs.zerotier.com/config/#local-configuration-options.
|
|
|
|
'';
|
|
|
|
example = {
|
|
|
|
settings.allowTcpFallbackRelay = false;
|
|
|
|
};
|
|
|
|
type = types.attrs;
|
|
|
|
};
|
|
|
|
|
2015-06-07 05:10:52 +01:00
|
|
|
config = mkIf cfg.enable {
|
|
|
|
systemd.services.zerotierone = {
|
|
|
|
description = "ZeroTierOne";
|
2019-05-20 13:06:12 +01:00
|
|
|
|
2015-06-07 05:10:52 +01:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
2019-05-20 13:06:12 +01:00
|
|
|
after = [ "network.target" ];
|
|
|
|
wants = [ "network-online.target" ];
|
|
|
|
|
|
|
|
path = [ cfg.package ];
|
|
|
|
|
2018-03-27 00:25:53 +01:00
|
|
|
preStart = ''
|
|
|
|
mkdir -p /var/lib/zerotier-one/networks.d
|
2015-06-07 05:10:52 +01:00
|
|
|
chmod 700 /var/lib/zerotier-one
|
|
|
|
chown -R root:root /var/lib/zerotier-one
|
2018-03-27 00:25:53 +01:00
|
|
|
'' + (concatMapStrings (netId: ''
|
|
|
|
touch "/var/lib/zerotier-one/networks.d/${netId}.conf"
|
2023-12-17 23:29:14 +00:00
|
|
|
'') cfg.joinNetworks) + ''
|
|
|
|
ln -s ${conf} /var/lib/zerotier-one/local.conf
|
|
|
|
'';
|
2015-06-07 05:10:52 +01:00
|
|
|
serviceConfig = {
|
2018-06-24 02:07:30 +01:00
|
|
|
ExecStart = "${cfg.package}/bin/zerotier-one -p${toString cfg.port}";
|
2016-02-19 22:56:19 +00:00
|
|
|
Restart = "always";
|
|
|
|
KillMode = "process";
|
2019-05-20 13:06:12 +01:00
|
|
|
TimeoutStopSec = 5;
|
2015-06-07 05:10:52 +01:00
|
|
|
};
|
|
|
|
};
|
2016-07-23 20:02:57 +01:00
|
|
|
|
|
|
|
# ZeroTier does not issue DHCP leases, but some strangers might...
|
2018-06-10 21:02:17 +01:00
|
|
|
networking.dhcpcd.denyInterfaces = [ "zt*" ];
|
2016-07-23 20:02:57 +01:00
|
|
|
|
2018-06-24 02:07:30 +01:00
|
|
|
# ZeroTier receives UDP transmissions
|
|
|
|
networking.firewall.allowedUDPPorts = [ cfg.port ];
|
2018-03-27 00:25:53 +01:00
|
|
|
|
2016-08-31 11:39:55 +01:00
|
|
|
environment.systemPackages = [ cfg.package ];
|
2020-01-09 22:34:54 +00:00
|
|
|
|
|
|
|
# Prevent systemd from potentially changing the MAC address
|
2020-03-10 23:26:51 +00:00
|
|
|
systemd.network.links."50-zerotier" = {
|
|
|
|
matchConfig = {
|
|
|
|
OriginalName = "zt*";
|
|
|
|
};
|
|
|
|
linkConfig = {
|
|
|
|
AutoNegotiation = false;
|
|
|
|
MACAddressPolicy = "none";
|
|
|
|
};
|
|
|
|
};
|
2015-06-07 05:10:52 +01:00
|
|
|
};
|
|
|
|
}
|