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.str;
45 default = "0.0.0.0";
46 description = ''
47 IP on which the server instance will listen for incoming voice connections. Defaults to any IP.
48 '';
49 };
50
51 defaultVoicePort = mkOption {
52 type = types.int;
53 default = 9987;
54 description = ''
55 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.
56 '';
57 };
58
59 fileTransferIP = mkOption {
60 type = types.str;
61 default = "0.0.0.0";
62 description = ''
63 IP on which the server instance will listen for incoming file transfer connections. Defaults to any IP.
64 '';
65 };
66
67 fileTransferPort = mkOption {
68 type = types.int;
69 default = 30033;
70 description = ''
71 TCP port opened for file transfers.
72 '';
73 };
74
75 queryIP = mkOption {
76 type = types.str;
77 default = "0.0.0.0";
78 description = ''
79 IP on which the server instance will listen for incoming ServerQuery connections. Defaults to any IP.
80 '';
81 };
82
83 queryPort = mkOption {
84 type = types.int;
85 default = 10011;
86 description = ''
87 TCP port opened for ServerQuery connections.
88 '';
89 };
90
91 };
92
93 };
94
95
96 ###### implementation
97
98 config = mkIf cfg.enable {
99 users.users.teamspeak = {
100 description = "Teamspeak3 voice communication server daemon";
101 group = group;
102 uid = config.ids.uids.teamspeak;
103 home = cfg.dataDir;
104 createHome = true;
105 };
106
107 users.groups.teamspeak = {
108 gid = config.ids.gids.teamspeak;
109 };
110
111 systemd.services.teamspeak3-server = {
112 description = "Teamspeak3 voice communication server daemon";
113 after = [ "network.target" ];
114 wantedBy = [ "multi-user.target" ];
115
116 preStart = ''
117 mkdir -p ${cfg.logPath}
118 chown ${user}:${group} ${cfg.logPath}
119 '';
120
121 serviceConfig = {
122 ExecStart = ''
123 ${ts3}/bin/ts3server \
124 dbsqlpath=${ts3}/lib/teamspeak/sql/ logpath=${cfg.logPath} \
125 voice_ip=${cfg.voiceIP} default_voice_port=${toString cfg.defaultVoicePort} \
126 filetransfer_ip=${cfg.fileTransferIP} filetransfer_port=${toString cfg.fileTransferPort} \
127 query_ip=${cfg.queryIP} query_port=${toString cfg.queryPort}
128 '';
129 WorkingDirectory = cfg.dataDir;
130 User = user;
131 Group = group;
132 PermissionsStartOnly = true;
133 };
134 };
135 };
136
137 meta.maintainers = with lib.maintainers; [ arobyn ];
138}