1 { config, lib, pkgs, ... }:
6 cfg = config.services.zerotierone;
9 options.services.zerotierone.enable = mkEnableOption (lib.mdDoc "ZeroTierOne");
11 options.services.zerotierone.joinNetworks = mkOption {
13 example = [ "a8a2c3c10c1a68de" ];
14 type = types.listOf types.str;
15 description = lib.mdDoc ''
16 List of ZeroTier Network IDs to join on startup
20 options.services.zerotierone.port = mkOption {
23 description = lib.mdDoc ''
24 Network port used by ZeroTier.
28 options.services.zerotierone.package = mkOption {
29 default = pkgs.zerotierone;
30 defaultText = literalExpression "pkgs.zerotierone";
32 description = lib.mdDoc ''
33 ZeroTier One package to use.
37 config = mkIf cfg.enable {
38 systemd.services.zerotierone = {
39 description = "ZeroTierOne";
41 wantedBy = [ "multi-user.target" ];
42 after = [ "network.target" ];
43 wants = [ "network-online.target" ];
45 path = [ cfg.package ];
48 mkdir -p /var/lib/zerotier-one/networks.d
49 chmod 700 /var/lib/zerotier-one
50 chown -R root:root /var/lib/zerotier-one
51 '' + (concatMapStrings (netId: ''
52 touch "/var/lib/zerotier-one/networks.d/${netId}.conf"
53 '') cfg.joinNetworks);
55 ExecStart = "${cfg.package}/bin/zerotier-one -p${toString cfg.port}";
62 # ZeroTier does not issue DHCP leases, but some strangers might...
63 networking.dhcpcd.denyInterfaces = [ "zt*" ];
65 # ZeroTier receives UDP transmissions
66 networking.firewall.allowedUDPPorts = [ cfg.port ];
68 environment.systemPackages = [ cfg.package ];
70 # Prevent systemd from potentially changing the MAC address
71 systemd.network.links."50-zerotier" = {
76 AutoNegotiation = false;
77 MACAddressPolicy = "none";