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 20 enable = mkOption { 21 type = types.bool; 22 default = false; 23 description = '' 24 Whether to run the Teamspeak3 voice communication server daemon. 25 ''; 26 }; 27 28 dataDir = mkOption { 29 type = types.path; 30 default = "/var/lib/teamspeak3-server"; 31 description = '' 32 Directory to store TS3 database and other state/data files. 33 ''; 34 }; 35 36 logPath = mkOption { 37 type = types.path; 38 default = "/var/log/teamspeak3-server/"; 39 description = '' 40 Directory to store log files in. 41 ''; 42 }; 43 44 voiceIP = mkOption { 45 type = types.str; 46 default = "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.str; 62 default = "0.0.0.0"; 63 description = '' 64 IP on which the server instance will listen for incoming file transfer connections. Defaults to any IP. 65 ''; 66 }; 67 68 fileTransferPort = mkOption { 69 type = types.int; 70 default = 30033; 71 description = '' 72 TCP port opened for file transfers. 73 ''; 74 }; 75 76 queryIP = mkOption { 77 type = types.str; 78 default = "0.0.0.0"; 79 description = '' 80 IP on which the server instance will listen for incoming ServerQuery connections. Defaults to any IP. 81 ''; 82 }; 83 84 queryPort = mkOption { 85 type = types.int; 86 default = 10011; 87 description = '' 88 TCP port opened for ServerQuery connections. 89 ''; 90 }; 91 92 }; 93 94 }; 95 96 97 ###### implementation 98 99 config = mkIf cfg.enable { 100 101 users.extraUsers.teamspeak = 102 { name = "teamspeak"; 103 description = "Teamspeak3 voice communication server daemon"; 104 group = group; 105 uid = config.ids.uids.teamspeak; 106 }; 107 108 users.extraGroups.teamspeak = 109 { name = "teamspeak"; 110 gid = config.ids.gids.teamspeak; 111 }; 112 113 systemd.services.teamspeak3-server = { 114 description = "Teamspeak3 voice communication server daemon"; 115 after = [ "network.target" ]; 116 wantedBy = [ "multi-user.target" ]; 117 118 preStart = '' 119 mkdir -p ${cfg.dataDir} 120 mkdir -p ${cfg.logPath} 121 chown ${user}:${group} ${cfg.dataDir} 122 chown ${user}:${group} ${cfg.logPath} 123 ''; 124 125 serviceConfig = 126 { ExecStart = '' 127 ${ts3}/bin/ts3server \ 128 dbsqlpath=${ts3}/lib/teamspeak/sql/ logpath=${cfg.logPath} \ 129 voice_ip=${cfg.voiceIP} default_voice_port=${toString cfg.defaultVoicePort} \ 130 filetransfer_ip=${cfg.fileTransferIP} filetransfer_port=${toString cfg.fileTransferPort} \ 131 query_ip=${cfg.queryIP} query_port=${toString cfg.queryPort} 132 ''; 133 WorkingDirectory = cfg.dataDir; 134 User = user; 135 Group = group; 136 PermissionsStartOnly = true; # preStart needs to run with root permissions 137 }; 138 }; 139 140 }; 141 142}