nixos/services.teeworlds: remove with lib; (#338053)

This commit is contained in:
Felix Bühler 2024-08-30 00:41:38 +02:00 committed by GitHub
commit dc8a0037ed
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,13 +1,10 @@
{ config, lib, pkgs, ... }: { config, lib, pkgs, ... }:
with lib;
let let
cfg = config.services.teeworlds; cfg = config.services.teeworlds;
register = cfg.register; register = cfg.register;
bool = b: if b != null && b then "1" else "0"; bool = b: if b != null && b then "1" else "0";
optionalSetting = s: setting: optionalString (s != null) "${setting} ${s}"; optionalSetting = s: setting: lib.optionalString (s != null) "${setting} ${s}";
lookup = attrs: key: default: if attrs ? key then attrs."${key}" else default; lookup = attrs: key: default: if attrs ? key then attrs."${key}" else default;
inactivePenaltyOptions = { inactivePenaltyOptions = {
@ -86,33 +83,33 @@ let
sv_vote_kick_bantime ${toString cfg.game.voteKickBanTime} sv_vote_kick_bantime ${toString cfg.game.voteKickBanTime}
sv_vote_kick_min ${toString cfg.game.voteKickMinimumPlayers} sv_vote_kick_min ${toString cfg.game.voteKickMinimumPlayers}
${concatStringsSep "\n" cfg.extraOptions} ${lib.concatStringsSep "\n" cfg.extraOptions}
''; '';
in in
{ {
options = { options = {
services.teeworlds = { services.teeworlds = {
enable = mkEnableOption "Teeworlds Server"; enable = lib.mkEnableOption "Teeworlds Server";
package = mkPackageOption pkgs "teeworlds-server" { }; package = lib.mkPackageOption pkgs "teeworlds-server" { };
openPorts = mkOption { openPorts = lib.mkOption {
type = types.bool; type = lib.types.bool;
default = false; default = false;
description = "Whether to open firewall ports for Teeworlds."; description = "Whether to open firewall ports for Teeworlds.";
}; };
name = mkOption { name = lib.mkOption {
type = types.str; type = lib.types.str;
default = "unnamed server"; default = "unnamed server";
description = '' description = ''
Name of the server. Name of the server.
''; '';
}; };
register = mkOption { register = lib.mkOption {
type = types.bool; type = lib.types.bool;
example = true; example = true;
default = false; default = false;
description = '' description = ''
@ -120,40 +117,40 @@ in
''; '';
}; };
motd = mkOption { motd = lib.mkOption {
type = types.nullOr types.str; type = lib.types.nullOr lib.types.str;
default = null; default = null;
description = '' description = ''
The server's message of the day text. The server's message of the day text.
''; '';
}; };
password = mkOption { password = lib.mkOption {
type = types.nullOr types.str; type = lib.types.nullOr lib.types.str;
default = null; default = null;
description = '' description = ''
Password to connect to the server. Password to connect to the server.
''; '';
}; };
rconPassword = mkOption { rconPassword = lib.mkOption {
type = types.nullOr types.str; type = lib.types.nullOr lib.types.str;
default = null; default = null;
description = '' description = ''
Password to access the remote console. If not set, a randomly generated one is displayed in the server log. Password to access the remote console. If not set, a randomly generated one is displayed in the server log.
''; '';
}; };
port = mkOption { port = lib.mkOption {
type = types.port; type = lib.types.port;
default = 8303; default = 8303;
description = '' description = ''
Port the server will listen on. Port the server will listen on.
''; '';
}; };
extraOptions = mkOption { extraOptions = lib.mkOption {
type = types.listOf types.str; type = lib.types.listOf lib.types.str;
default = []; default = [];
description = '' description = ''
Extra configuration lines for the {file}`teeworlds.cfg`. See [Teeworlds Documentation](https://www.teeworlds.com/?page=docs&wiki=server_settings). Extra configuration lines for the {file}`teeworlds.cfg`. See [Teeworlds Documentation](https://www.teeworlds.com/?page=docs&wiki=server_settings).
@ -162,32 +159,32 @@ in
}; };
server = { server = {
bindAddr = mkOption { bindAddr = lib.mkOption {
type = types.nullOr types.str; type = lib.types.nullOr lib.types.str;
default = null; default = null;
description = '' description = ''
The address the server will bind to. The address the server will bind to.
''; '';
}; };
enableHighBandwidth = mkOption { enableHighBandwidth = lib.mkOption {
type = types.bool; type = lib.types.bool;
default = false; default = false;
description = '' description = ''
Whether to enable high bandwidth mode on LAN servers. This will double the amount of bandwidth required for running the server. Whether to enable high bandwidth mode on LAN servers. This will double the amount of bandwidth required for running the server.
''; '';
}; };
hostName = mkOption { hostName = lib.mkOption {
type = types.nullOr types.str; type = lib.types.nullOr lib.types.str;
default = null; default = null;
description = '' description = ''
Hostname for the server. Hostname for the server.
''; '';
}; };
inactivePenalty = mkOption { inactivePenalty = lib.mkOption {
type = types.enum [ "spectator" "spectator/kick" "kick" ]; type = lib.types.enum [ "spectator" "spectator/kick" "kick" ];
example = "spectator"; example = "spectator";
default = "spectator/kick"; default = "spectator/kick";
description = '' description = ''
@ -201,48 +198,48 @@ in
''; '';
}; };
kickInactiveSpectators = mkOption { kickInactiveSpectators = lib.mkOption {
type = types.bool; type = lib.types.bool;
default = false; default = false;
description = '' description = ''
Whether to kick inactive spectators. Whether to kick inactive spectators.
''; '';
}; };
inactiveTime = mkOption { inactiveTime = lib.mkOption {
type = types.ints.unsigned; type = lib.types.ints.unsigned;
default = 3; default = 3;
description = '' description = ''
The amount of minutes a client has to idle before it is considered inactive. The amount of minutes a client has to idle before it is considered inactive.
''; '';
}; };
maxClients = mkOption { maxClients = lib.mkOption {
type = types.ints.unsigned; type = lib.types.ints.unsigned;
default = 12; default = 12;
description = '' description = ''
The maximum amount of clients that can be connected to the server at the same time. The maximum amount of clients that can be connected to the server at the same time.
''; '';
}; };
maxClientsPerIP = mkOption { maxClientsPerIP = lib.mkOption {
type = types.ints.unsigned; type = lib.types.ints.unsigned;
default = 12; default = 12;
description = '' description = ''
The maximum amount of clients with the same IP address that can be connected to the server at the same time. The maximum amount of clients with the same IP address that can be connected to the server at the same time.
''; '';
}; };
skillLevel = mkOption { skillLevel = lib.mkOption {
type = types.enum [ "casual" "normal" "competitive" ]; type = lib.types.enum [ "casual" "normal" "competitive" ];
default = "normal"; default = "normal";
description = '' description = ''
The skill level shown in the server browser. The skill level shown in the server browser.
''; '';
}; };
enableSpamProtection = mkOption { enableSpamProtection = lib.mkOption {
type = types.bool; type = lib.types.bool;
default = true; default = true;
description = '' description = ''
Whether to enable chat spam protection. Whether to enable chat spam protection.
@ -251,8 +248,8 @@ in
}; };
game = { game = {
gameType = mkOption { gameType = lib.mkOption {
type = types.str; type = lib.types.str;
example = "ctf"; example = "ctf";
default = "dm"; default = "dm";
description = '' description = ''
@ -262,8 +259,8 @@ in
''; '';
}; };
map = mkOption { map = lib.mkOption {
type = types.str; type = lib.types.str;
example = "ctf5"; example = "ctf5";
default = "dm1"; default = "dm1";
description = '' description = ''
@ -271,16 +268,16 @@ in
''; '';
}; };
swapTeams = mkOption { swapTeams = lib.mkOption {
type = types.bool; type = lib.types.bool;
default = true; default = true;
description = '' description = ''
Whether to swap teams each round. Whether to swap teams each round.
''; '';
}; };
enableReadyMode = mkOption { enableReadyMode = lib.mkOption {
type = types.bool; type = lib.types.bool;
default = false; default = false;
description = '' description = ''
Whether to enable "ready mode"; where players can pause/unpause the game Whether to enable "ready mode"; where players can pause/unpause the game
@ -288,24 +285,24 @@ in
''; '';
}; };
playerSlots = mkOption { playerSlots = lib.mkOption {
type = types.ints.unsigned; type = lib.types.ints.unsigned;
default = 8; default = 8;
description = '' description = ''
The amount of slots to reserve for players (as opposed to spectators). The amount of slots to reserve for players (as opposed to spectators).
''; '';
}; };
enablePowerups = mkOption { enablePowerups = lib.mkOption {
type = types.bool; type = lib.types.bool;
default = true; default = true;
description = '' description = ''
Whether to allow powerups such as the ninja. Whether to allow powerups such as the ninja.
''; '';
}; };
scoreLimit = mkOption { scoreLimit = lib.mkOption {
type = types.ints.unsigned; type = lib.types.ints.unsigned;
example = 400; example = 400;
default = 20; default = 20;
description = '' description = ''
@ -313,24 +310,24 @@ in
''; '';
}; };
restrictSpectators = mkOption { restrictSpectators = lib.mkOption {
type = types.bool; type = lib.types.bool;
default = false; default = false;
description = '' description = ''
Whether to restrict access to information such as health, ammo and armour in spectator mode. Whether to restrict access to information such as health, ammo and armour in spectator mode.
''; '';
}; };
enableTeamDamage = mkOption { enableTeamDamage = lib.mkOption {
type = types.bool; type = lib.types.bool;
default = false; default = false;
description = '' description = ''
Whether to enable team damage; whether to allow team mates to inflict damage on one another. Whether to enable team damage; whether to allow team mates to inflict damage on one another.
''; '';
}; };
timeLimit = mkOption { timeLimit = lib.mkOption {
type = types.ints.unsigned; type = lib.types.ints.unsigned;
default = 0; default = 0;
description = '' description = ''
Time limit of the game. In cases of equal points, there will be sudden death. Time limit of the game. In cases of equal points, there will be sudden death.
@ -338,8 +335,8 @@ in
''; '';
}; };
tournamentMode = mkOption { tournamentMode = lib.mkOption {
type = types.enum [ "disable" "enable" "restrictSpectators" ]; type = lib.types.enum [ "disable" "enable" "restrictSpectators" ];
default = "disable"; default = "disable";
description = '' description = ''
Whether to enable tournament mode. In tournament mode, players join as spectators. Whether to enable tournament mode. In tournament mode, players join as spectators.
@ -347,24 +344,24 @@ in
''; '';
}; };
enableVoteKick = mkOption { enableVoteKick = lib.mkOption {
type = types.bool; type = lib.types.bool;
default = true; default = true;
description = '' description = ''
Whether to enable voting to kick players. Whether to enable voting to kick players.
''; '';
}; };
voteKickBanTime = mkOption { voteKickBanTime = lib.mkOption {
type = types.ints.unsigned; type = lib.types.ints.unsigned;
default = 5; default = 5;
description = '' description = ''
The amount of minutes that a player is banned for if they get kicked by a vote. The amount of minutes that a player is banned for if they get kicked by a vote.
''; '';
}; };
voteKickMinimumPlayers = mkOption { voteKickMinimumPlayers = lib.mkOption {
type = types.ints.unsigned; type = lib.types.ints.unsigned;
default = 5; default = 5;
description = '' description = ''
The minimum amount of players required to start a kick vote. The minimum amount of players required to start a kick vote.
@ -374,8 +371,8 @@ in
}; };
}; };
config = mkIf cfg.enable { config = lib.mkIf cfg.enable {
networking.firewall = mkIf cfg.openPorts { networking.firewall = lib.mkIf cfg.openPorts {
allowedUDPPorts = [ cfg.port ]; allowedUDPPorts = [ cfg.port ];
}; };