aboutsummaryrefslogtreecommitdiff
path: root/nixpkgs/nixos/modules/services/games
diff options
context:
space:
mode:
Diffstat (limited to 'nixpkgs/nixos/modules/services/games')
-rw-r--r--nixpkgs/nixos/modules/services/games/minetest-server.nix16
-rw-r--r--nixpkgs/nixos/modules/services/games/teeworlds.nix119
-rw-r--r--nixpkgs/nixos/modules/services/games/terraria.nix20
3 files changed, 140 insertions, 15 deletions
diff --git a/nixpkgs/nixos/modules/services/games/minetest-server.nix b/nixpkgs/nixos/modules/services/games/minetest-server.nix
index 98e69c6dc0e..f52079fc1ef 100644
--- a/nixpkgs/nixos/modules/services/games/minetest-server.nix
+++ b/nixpkgs/nixos/modules/services/games/minetest-server.nix
@@ -5,12 +5,12 @@ with lib;
let
cfg = config.services.minetest-server;
flag = val: name: if val != null then "--${name} ${val} " else "";
- flags = [
- (flag cfg.gameId "gameid")
- (flag cfg.world "world")
- (flag cfg.configPath "config")
- (flag cfg.logPath "logfile")
- (flag cfg.port "port")
+ flags = [
+ (flag cfg.gameId "gameid")
+ (flag cfg.world "world")
+ (flag cfg.configPath "config")
+ (flag cfg.logPath "logfile")
+ (flag cfg.port "port")
];
in
{
@@ -26,7 +26,7 @@ in
type = types.nullOr types.str;
default = null;
description = ''
- Id of the game to use. To list available games run
+ Id of the game to use. To list available games run
`minetestserver --gameid list`.
If only one game exists, this option can be null.
@@ -59,7 +59,7 @@ in
type = types.nullOr types.path;
default = null;
description = ''
- Path to logfile for logging.
+ Path to logfile for logging.
If set to null, logging will be output to stdout which means
all output will be catched by systemd.
diff --git a/nixpkgs/nixos/modules/services/games/teeworlds.nix b/nixpkgs/nixos/modules/services/games/teeworlds.nix
new file mode 100644
index 00000000000..babf989c98c
--- /dev/null
+++ b/nixpkgs/nixos/modules/services/games/teeworlds.nix
@@ -0,0 +1,119 @@
+{ config, lib, pkgs, ... }:
+
+with lib;
+
+let
+ cfg = config.services.teeworlds;
+ register = cfg.register;
+
+ teeworldsConf = pkgs.writeText "teeworlds.cfg" ''
+ sv_port ${toString cfg.port}
+ sv_register ${if cfg.register then "1" else "0"}
+ ${optionalString (cfg.name != null) "sv_name ${cfg.name}"}
+ ${optionalString (cfg.motd != null) "sv_motd ${cfg.motd}"}
+ ${optionalString (cfg.password != null) "password ${cfg.password}"}
+ ${optionalString (cfg.rconPassword != null) "sv_rcon_password ${cfg.rconPassword}"}
+ ${concatStringsSep "\n" cfg.extraOptions}
+ '';
+
+in
+{
+ options = {
+ services.teeworlds = {
+ enable = mkEnableOption "Teeworlds Server";
+
+ openPorts = mkOption {
+ type = types.bool;
+ default = false;
+ description = "Whether to open firewall ports for Teeworlds";
+ };
+
+ name = mkOption {
+ type = types.nullOr types.str;
+ default = null;
+ description = ''
+ Name of the server. Defaults to 'unnamed server'.
+ '';
+ };
+
+ register = mkOption {
+ type = types.bool;
+ example = true;
+ default = false;
+ description = ''
+ Whether the server registers as public server in the global server list. This is disabled by default because of privacy.
+ '';
+ };
+
+ motd = mkOption {
+ type = types.nullOr types.str;
+ default = null;
+ description = ''
+ Set the server message of the day text.
+ '';
+ };
+
+ password = mkOption {
+ type = types.nullOr types.str;
+ default = null;
+ description = ''
+ Password to connect to the server.
+ '';
+ };
+
+ rconPassword = mkOption {
+ type = types.nullOr types.str;
+ default = null;
+ description = ''
+ Password to access the remote console. If not set, a randomly generated one is displayed in the server log.
+ '';
+ };
+
+ port = mkOption {
+ type = types.int;
+ default = 8303;
+ description = ''
+ Port the server will listen on.
+ '';
+ };
+
+ extraOptions = mkOption {
+ type = types.listOf types.str;
+ default = [];
+ description = ''
+ Extra configuration lines for the <filename>teeworlds.cfg</filename>. See <link xlink:href="https://www.teeworlds.com/?page=docs&amp;wiki=server_settings">Teeworlds Documentation</link>.
+ '';
+ example = [ "sv_map dm1" "sv_gametype dm" ];
+ };
+ };
+ };
+
+ config = mkIf cfg.enable {
+ networking.firewall = mkIf cfg.openPorts {
+ allowedUDPPorts = [ cfg.port ];
+ };
+
+ systemd.services.teeworlds = {
+ description = "Teeworlds Server";
+ wantedBy = [ "multi-user.target" ];
+ after = [ "network.target" ];
+
+ serviceConfig = {
+ DynamicUser = true;
+ ExecStart = "${pkgs.teeworlds}/bin/teeworlds_srv -f ${teeworldsConf}";
+
+ # Hardening
+ CapabilityBoundingSet = false;
+ PrivateDevices = true;
+ PrivateUsers = true;
+ ProtectHome = true;
+ ProtectKernelLogs = true;
+ ProtectKernelModules = true;
+ ProtectKernelTunables = true;
+ RestrictAddressFamilies = [ "AF_INET" "AF_INET6" ];
+ RestrictNamespaces = true;
+ SystemCallArchitectures = "native";
+ };
+ };
+ };
+}
diff --git a/nixpkgs/nixos/modules/services/games/terraria.nix b/nixpkgs/nixos/modules/services/games/terraria.nix
index a59b74c0b4c..34c8ff137d6 100644
--- a/nixpkgs/nixos/modules/services/games/terraria.nix
+++ b/nixpkgs/nixos/modules/services/games/terraria.nix
@@ -7,7 +7,7 @@ let
worldSizeMap = { small = 1; medium = 2; large = 3; };
valFlag = name: val: optionalString (val != null) "-${name} \"${escape ["\\" "\""] (toString val)}\"";
boolFlag = name: val: optionalString val "-${name}";
- flags = [
+ flags = [
(valFlag "port" cfg.port)
(valFlag "maxPlayers" cfg.maxPlayers)
(valFlag "password" cfg.password)
@@ -25,7 +25,7 @@ let
exit 0
fi
- ${getBin pkgs.tmux}/bin/tmux -S /var/lib/terraria/terraria.sock send-keys Enter exit Enter
+ ${getBin pkgs.tmux}/bin/tmux -S ${cfg.dataDir}/terraria.sock send-keys Enter exit Enter
${getBin pkgs.coreutils}/bin/tail --pid="$1" -f /dev/null
'';
in
@@ -36,7 +36,7 @@ in
type = types.bool;
default = false;
description = ''
- If enabled, starts a Terraria server. The server can be connected to via <literal>tmux -S /var/lib/terraria/terraria.sock attach</literal>
+ If enabled, starts a Terraria server. The server can be connected to via <literal>tmux -S ${cfg.dataDir}/terraria.sock attach</literal>
for administration by users who are a part of the <literal>terraria</literal> group (use <literal>C-b d</literal> shortcut to detach again).
'';
};
@@ -111,13 +111,19 @@ in
default = false;
description = "Disables automatic Universal Plug and Play.";
};
+ dataDir = mkOption {
+ type = types.str;
+ default = "/var/lib/terraria";
+ example = "/srv/terraria";
+ description = "Path to variable state data directory for terraria.";
+ };
};
};
config = mkIf cfg.enable {
users.users.terraria = {
description = "Terraria server service user";
- home = "/var/lib/terraria";
+ home = cfg.dataDir;
createHome = true;
uid = config.ids.uids.terraria;
};
@@ -136,13 +142,13 @@ in
User = "terraria";
Type = "forking";
GuessMainPID = true;
- ExecStart = "${getBin pkgs.tmux}/bin/tmux -S /var/lib/terraria/terraria.sock new -d ${pkgs.terraria-server}/bin/TerrariaServer ${concatStringsSep " " flags}";
+ ExecStart = "${getBin pkgs.tmux}/bin/tmux -S ${cfg.dataDir}/terraria.sock new -d ${pkgs.terraria-server}/bin/TerrariaServer ${concatStringsSep " " flags}";
ExecStop = "${stopScript} $MAINPID";
};
postStart = ''
- ${pkgs.coreutils}/bin/chmod 660 /var/lib/terraria/terraria.sock
- ${pkgs.coreutils}/bin/chgrp terraria /var/lib/terraria/terraria.sock
+ ${pkgs.coreutils}/bin/chmod 660 ${cfg.dataDir}/terraria.sock
+ ${pkgs.coreutils}/bin/chgrp terraria ${cfg.dataDir}/terraria.sock
'';
};
};