9 cfg = config.services.zeronsd;
10 settingsFormat = pkgs.formats.json { };
13 options.services.zeronsd.servedNetworks = lib.mkOption {
16 "a8a2c3c10c1a68de".settings.token = "/var/lib/zeronsd/apitoken";
18 description = "ZeroTier Networks to start zeronsd instances for.";
19 type = lib.types.attrsOf (
22 package = lib.mkPackageOption pkgs "zeronsd" { };
24 settings = lib.mkOption {
25 description = "Settings for zeronsd";
27 type = lib.types.submodule {
28 freeformType = settingsFormat.type;
31 domain = lib.mkOption {
32 default = "home.arpa";
33 type = lib.types.singleLineStr;
34 description = "Domain under which ZeroTier records will be available.";
37 token = lib.mkOption {
38 type = lib.types.path;
39 description = "Path to a file containing the API Token for ZeroTier Central.";
42 log_level = lib.mkOption {
44 type = lib.types.enum [
52 description = "Log Level.";
55 wildcard = lib.mkOption {
57 type = lib.types.bool;
58 description = "Whether to serve a wildcard record for ZeroTier Nodes.";
68 config = lib.mkIf (cfg.servedNetworks != { }) {
71 assertion = config.services.zerotierone.enable;
72 message = "zeronsd needs a configured zerotier-one";
76 systemd.services = lib.mapAttrs' (netname: netcfg: {
77 name = "zeronsd-${netname}";
79 description = "ZeroTier DNS server for Network ${netname}";
81 wantedBy = [ "multi-user.target" ];
86 wants = [ "network-online.target" ];
90 configFile = pkgs.writeText "zeronsd.json" (builtins.toJSON netcfg.settings);
93 ExecStart = "${netcfg.package}/bin/zeronsd start --config ${configFile} --config-type json ${netname}";
94 Restart = "on-failure";
99 AmbientCapabilities = "CAP_NET_BIND_SERVICE";
102 }) cfg.servedNetworks;
104 systemd.tmpfiles.rules = [
105 "a+ /var/lib/zerotier-one - - - - u:zeronsd:x"
106 "a+ /var/lib/zerotier-one/authtoken.secret - - - - mask::r,u:zeronsd:r"
109 users.users.zeronsd = {
111 description = "Service user for running zeronsd";
115 users.groups.zeronsd = { };