feat: zomboid: server but you cannot connect to it

This commit is contained in:
2026-08-27 19:37:33 +00:00
parent cadc6c44be
commit 31cac93a4c
3 changed files with 35 additions and 3 deletions
@@ -16,10 +16,13 @@
name: value: name: value:
"${name}=${if builtins.isBool value then lib.boolToString value else toString value}" "${name}=${if builtins.isBool value then lib.boolToString value else toString value}"
) serverProperties; ) serverProperties;
adminPasswordFile = "${cfg.dataDir}/admin-password";
startScript = pkgs.writeShellScript "project-zomboid-start" '' startScript = pkgs.writeShellScript "project-zomboid-start" ''
exec ${lib.escapeShellArg "${cfg.installDir}/start-server.sh"} \ admin_password=$(${pkgs.coreutils}/bin/cat ${lib.escapeShellArg adminPasswordFile})
exec ${pkgs.steam-run}/bin/steam-run \
${lib.escapeShellArg "${cfg.installDir}/start-server.sh"} \
-servername ${lib.escapeShellArg cfg.serverName} \ -servername ${lib.escapeShellArg cfg.serverName} \
-cachedir ${lib.escapeShellArg cfg.dataDir} -adminpassword "$admin_password"
''; '';
in { in {
options.hectic.services."project-zomboid" = { options.hectic.services."project-zomboid" = {
@@ -61,6 +64,12 @@ in {
description = "Steam beta branch, for example legacy41."; description = "Steam beta branch, for example legacy41.";
}; };
memory = lib.mkOption {
type = lib.types.strMatching "[0-9]+[mMgG]";
default = "3g";
description = "Maximum Java heap for the server, for example 3g.";
};
workshopItems = lib.mkOption { workshopItems = lib.mkOption {
type = lib.types.listOf lib.types.str; type = lib.types.listOf lib.types.str;
default = [ ]; default = [ ];
@@ -121,11 +130,18 @@ in {
preStart = '' preStart = ''
${pkgs.coreutils}/bin/install -d -m 0750 \ ${pkgs.coreutils}/bin/install -d -m 0750 \
${lib.escapeShellArg cfg.installDir} ${lib.escapeShellArg cfg.installDir}
if [ ! -s ${lib.escapeShellArg adminPasswordFile} ]; then
umask 077
${pkgs.openssl}/bin/openssl rand -base64 32 > ${lib.escapeShellArg adminPasswordFile}
fi
${pkgs.steamcmd}/bin/steamcmd \ ${pkgs.steamcmd}/bin/steamcmd \
+force_install_dir ${lib.escapeShellArg cfg.installDir} \ +force_install_dir ${lib.escapeShellArg cfg.installDir} \
+login anonymous \ +login anonymous \
+app_update 380870 ${lib.optionalString (cfg.branch != null) "-beta ${lib.escapeShellArg cfg.branch}"} validate \ +app_update 380870 ${lib.optionalString (cfg.branch != null) "-beta ${lib.escapeShellArg cfg.branch}"} validate \
+quit +quit
${pkgs.gnused}/bin/sed -i -E \
's/"-Xmx[0-9]+[mMgG]"/"-Xmx${cfg.memory}"/' \
${lib.escapeShellArg "${cfg.installDir}/ProjectZomboid64.json"}
${pkgs.coreutils}/bin/install -d -m 0750 \ ${pkgs.coreutils}/bin/install -d -m 0750 \
${lib.escapeShellArg "${cfg.dataDir}/Server"} ${lib.escapeShellArg "${cfg.dataDir}/Server"}
{ {
@@ -146,7 +162,6 @@ in {
"SteamAppId=380870" "SteamAppId=380870"
]; ];
ExecStart = startScript; ExecStart = startScript;
ExecStop = "-${pkgs.coreutils}/bin/kill -INT $MAINPID";
Restart = "on-failure"; Restart = "on-failure";
RestartSec = 5; RestartSec = 5;
TimeoutStopSec = 30; TimeoutStopSec = 30;
+2
View File
@@ -12,6 +12,8 @@ in self.lib.nixpkgs-lib.nixosSystem {
pkgs = import inputs.nixpkgs { pkgs = import inputs.nixpkgs {
inherit system; inherit system;
overlays = [ self.overlays.default ]; overlays = [ self.overlays.default ];
config.allowUnfreePredicate = pkg:
builtins.elem (inputs.nixpkgs.lib.getName pkg) [ "steamcmd" "steam-unwrapped" ];
}; };
modules = [ modules = [
{ networking.hostName = name; } { networking.hostName = name; }
+15
View File
@@ -92,6 +92,13 @@ in {
services.matrix = { services.matrix = {
enable = false; enable = false;
}; };
services."project-zomboid" = {
enable = true;
memory = "3g";
serverName = "servertest";
workshopItems = [ ];
mods = [ ];
};
services.gitea-runner-controller = { services.gitea-runner-controller = {
# NOTE(yukkop): ephemeral Hetzner VM runners (1 VM = 1 job). # NOTE(yukkop): ephemeral Hetzner VM runners (1 VM = 1 job).
# Runbook: infra/gitea-runners/runbook.md "Ephemeral VM runner cutover". # Runbook: infra/gitea-runners/runbook.md "Ephemeral VM runner cutover".
@@ -107,6 +114,14 @@ in {
}; };
}; };
zramSwap = {
enable = true;
priority = 100;
algorithm = lib.mkDefault "zstd";
swapDevices = 1;
memoryPercent = lib.mkDefault 100;
};
# NOTE(yukkop): disk was provisioned by Hetzner rescue image, disko was never # NOTE(yukkop): disk was provisioned by Hetzner rescue image, disko was never
# run, so partition labels don't exist. Override fileSystems with actual UUIDs. # run, so partition labels don't exist. Override fileSystems with actual UUIDs.
fileSystems."/" = lib.mkForce { fileSystems."/" = lib.mkForce {