1 { config, lib, pkgs, ... }:
6 ts3 = pkgs.teamspeak_server;
7 cfg = config.services.teamspeak3;
18 services.teamspeak3 = {
23 Whether to run the Teamspeak3 voice communication server daemon.
29 default = "/var/lib/teamspeak3-server";
31 Directory to store TS3 database and other state/data files.
37 default = "/var/log/teamspeak3-server/";
39 Directory to store log files in.
44 type = types.nullOr types.str;
48 IP on which the server instance will listen for incoming voice connections. Defaults to any IP.
52 defaultVoicePort = mkOption {
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.
60 fileTransferIP = mkOption {
61 type = types.nullOr types.str;
65 IP on which the server instance will listen for incoming file transfer connections. Defaults to any IP.
69 fileTransferPort = mkOption {
73 TCP port opened for file transfers.
78 type = types.nullOr types.str;
82 IP on which the server instance will listen for incoming ServerQuery connections. Defaults to any IP.
86 queryPort = mkOption {
90 TCP port opened for ServerQuery connections using the raw telnet protocol.
94 querySshPort = mkOption {
98 TCP port opened for ServerQuery connections using the SSH protocol.
102 queryHttpPort = mkOption {
106 TCP port opened for ServerQuery connections using the HTTP protocol.
110 openFirewall = mkOption {
113 description = "Open ports in the firewall for the TeamSpeak3 server.";
116 openFirewallServerQuery = mkOption {
119 description = "Open ports in the firewall for the TeamSpeak3 serverquery (administration) system. Requires openFirewall.";
127 ###### implementation
129 config = mkIf cfg.enable {
130 users.users.teamspeak = {
131 description = "Teamspeak3 voice communication server daemon";
133 uid = config.ids.uids.teamspeak;
138 users.groups.teamspeak = {
139 gid = config.ids.gids.teamspeak;
142 systemd.tmpfiles.rules = [
143 "d '${cfg.logPath}' - ${user} ${group} - -"
146 networking.firewall = mkIf cfg.openFirewall {
147 allowedTCPPorts = [ cfg.fileTransferPort ] ++ (map (port:
148 mkIf cfg.openFirewallServerQuery port
149 ) [cfg.queryPort cfg.querySshPort cfg.queryHttpPort]);
150 # subsequent vServers will use the incremented voice port, let's just open the next 10
151 allowedUDPPortRanges = [ { from = cfg.defaultVoicePort; to = cfg.defaultVoicePort + 10; } ];
154 systemd.services.teamspeak3-server = {
155 description = "Teamspeak3 voice communication server daemon";
156 after = [ "network.target" ];
157 wantedBy = [ "multi-user.target" ];
161 ${ts3}/bin/ts3server \
162 dbsqlpath=${ts3}/lib/teamspeak/sql/ \
163 logpath=${cfg.logPath} \
165 default_voice_port=${toString cfg.defaultVoicePort} \
166 filetransfer_port=${toString cfg.fileTransferPort} \
167 query_port=${toString cfg.queryPort} \
168 query_ssh_port=${toString cfg.querySshPort} \
169 query_http_port=${toString cfg.queryHttpPort} \
170 ${optionalString (cfg.voiceIP != null) "voice_ip=${cfg.voiceIP}"} \
171 ${optionalString (cfg.fileTransferIP != null) "filetransfer_ip=${cfg.fileTransferIP}"} \
172 ${optionalString (cfg.queryIP != null) "query_ip=${cfg.queryIP}"} \
173 ${optionalString (cfg.queryIP != null) "query_ssh_ip=${cfg.queryIP}"} \
174 ${optionalString (cfg.queryIP != null) "query_http_ip=${cfg.queryIP}"} \
176 WorkingDirectory = cfg.dataDir;
179 Restart = "on-failure";
184 meta.maintainers = with lib.maintainers; [ arobyn ];