1 { config, lib, pkgs, ... }:
6 ts3 = pkgs.teamspeak_server;
7 cfg = config.services.teamspeak3;
18 services.teamspeak3 = {
22 description = lib.mdDoc ''
23 Whether to run the Teamspeak3 voice communication server daemon.
29 default = "/var/lib/teamspeak3-server";
30 description = lib.mdDoc ''
31 Directory to store TS3 database and other state/data files.
37 default = "/var/log/teamspeak3-server/";
38 description = lib.mdDoc ''
39 Directory to store log files in.
44 type = types.nullOr types.str;
47 description = lib.mdDoc ''
48 IP on which the server instance will listen for incoming voice connections. Defaults to any IP.
52 defaultVoicePort = mkOption {
55 description = lib.mdDoc ''
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;
64 description = lib.mdDoc ''
65 IP on which the server instance will listen for incoming file transfer connections. Defaults to any IP.
69 fileTransferPort = mkOption {
72 description = lib.mdDoc ''
73 TCP port opened for file transfers.
78 type = types.nullOr types.str;
81 description = lib.mdDoc ''
82 IP on which the server instance will listen for incoming ServerQuery connections. Defaults to any IP.
86 queryPort = mkOption {
89 description = lib.mdDoc ''
90 TCP port opened for ServerQuery connections.
94 openFirewall = mkOption {
97 description = lib.mdDoc "Open ports in the firewall for the TeamSpeak3 server.";
100 openFirewallServerQuery = mkOption {
103 description = lib.mdDoc "Open ports in the firewall for the TeamSpeak3 serverquery (administration) system. Requires openFirewall.";
111 ###### implementation
113 config = mkIf cfg.enable {
114 users.users.teamspeak = {
115 description = "Teamspeak3 voice communication server daemon";
117 uid = config.ids.uids.teamspeak;
122 users.groups.teamspeak = {
123 gid = config.ids.gids.teamspeak;
126 systemd.tmpfiles.rules = [
127 "d '${cfg.logPath}' - ${user} ${group} - -"
130 networking.firewall = mkIf cfg.openFirewall {
131 allowedTCPPorts = [ cfg.fileTransferPort ] ++ optionals (cfg.openFirewallServerQuery) [ cfg.queryPort (cfg.queryPort + 11) ];
132 # subsequent vServers will use the incremented voice port, let's just open the next 10
133 allowedUDPPortRanges = [ { from = cfg.defaultVoicePort; to = cfg.defaultVoicePort + 10; } ];
136 systemd.services.teamspeak3-server = {
137 description = "Teamspeak3 voice communication server daemon";
138 after = [ "network.target" ];
139 wantedBy = [ "multi-user.target" ];
143 ${ts3}/bin/ts3server \
144 dbsqlpath=${ts3}/lib/teamspeak/sql/ logpath=${cfg.logPath} \
145 ${optionalString (cfg.voiceIP != null) "voice_ip=${cfg.voiceIP}"} \
146 default_voice_port=${toString cfg.defaultVoicePort} \
147 ${optionalString (cfg.fileTransferIP != null) "filetransfer_ip=${cfg.fileTransferIP}"} \
148 filetransfer_port=${toString cfg.fileTransferPort} \
149 ${optionalString (cfg.queryIP != null) "query_ip=${cfg.queryIP}"} \
150 query_port=${toString cfg.queryPort} license_accepted=1
152 WorkingDirectory = cfg.dataDir;
155 Restart = "on-failure";
160 meta.maintainers = with lib.maintainers; [ arobyn ];