1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6 ts3 = pkgs.teamspeak_server;
7 cfg = config.services.teamspeak3;
8 user = "teamspeak";
9 group = "teamspeak";
10in
11
12{
13
14 ###### interface
15
16 options = {
17
18 services.teamspeak3 = {
19 enable = mkOption {
20 type = types.bool;
21 default = false;
22 description = ''
23 Whether to run the Teamspeak3 voice communication server daemon.
24 '';
25 };
26
27 dataDir = mkOption {
28 type = types.path;
29 default = "/var/lib/teamspeak3-server";
30 description = ''
31 Directory to store TS3 database and other state/data files.
32 '';
33 };
34
35 logPath = mkOption {
36 type = types.path;
37 default = "/var/log/teamspeak3-server/";
38 description = ''
39 Directory to store log files in.
40 '';
41 };
42
43 voiceIP = mkOption {
44 type = types.nullOr types.str;
45 default = null;
46 example = "0.0.0.0";
47 description = ''
48 IP on which the server instance will listen for incoming voice connections. Defaults to any IP.
49 '';
50 };
51
52 defaultVoicePort = mkOption {
53 type = types.int;
54 default = 9987;
55 description = ''
56 Default UDP port for clients to connect to virtual servers - used for first virtual server, subsequent ones will open on incrementing port numbers by default.
57 '';
58 };
59
60 fileTransferIP = mkOption {
61 type = types.nullOr types.str;
62 default = null;
63 example = "0.0.0.0";
64 description = ''
65 IP on which the server instance will listen for incoming file transfer connections. Defaults to any IP.
66 '';
67 };
68
69 fileTransferPort = mkOption {
70 type = types.int;
71 default = 30033;
72 description = ''
73 TCP port opened for file transfers.
74 '';
75 };
76
77 queryIP = mkOption {
78 type = types.nullOr types.str;
79 default = null;
80 example = "0.0.0.0";
81 description = ''
82 IP on which the server instance will listen for incoming ServerQuery connections. Defaults to any IP.
83 '';
84 };
85
86 queryPort = mkOption {
87 type = types.int;
88 default = 10011;
89 description = ''
90 TCP port opened for ServerQuery connections.
91 '';
92 };
93
94 };
95
96 };
97
98
99 ###### implementation
100
101 config = mkIf cfg.enable {
102 users.users.teamspeak = {
103 description = "Teamspeak3 voice communication server daemon";
104 group = group;
105 uid = config.ids.uids.teamspeak;
106 home = cfg.dataDir;
107 createHome = true;
108 };
109
110 users.groups.teamspeak = {
111 gid = config.ids.gids.teamspeak;
112 };
113
114 systemd.tmpfiles.rules = [
115 "d '${cfg.logPath}' - ${user} ${group} - -"
116 ];
117
118 systemd.services.teamspeak3-server = {
119 description = "Teamspeak3 voice communication server daemon";
120 after = [ "network.target" ];
121 wantedBy = [ "multi-user.target" ];
122
123 serviceConfig = {
124 ExecStart = ''
125 ${ts3}/bin/ts3server \
126 dbsqlpath=${ts3}/lib/teamspeak/sql/ logpath=${cfg.logPath} \
127 ${optionalString (cfg.voiceIP != null) "voice_ip=${cfg.voiceIP}"} \
128 default_voice_port=${toString cfg.defaultVoicePort} \
129 ${optionalString (cfg.fileTransferIP != null) "filetransfer_ip=${cfg.fileTransferIP}"} \
130 filetransfer_port=${toString cfg.fileTransferPort} \
131 ${optionalString (cfg.queryIP != null) "query_ip=${cfg.queryIP}"} \
132 query_port=${toString cfg.queryPort} license_accepted=1
133 '';
134 WorkingDirectory = cfg.dataDir;
135 User = user;
136 Group = group;
137 };
138 };
139 };
140
141 meta.maintainers = with lib.maintainers; [ arobyn ];
142}