Files
hearth/nixos/system/neuro/project-zomboid.nix
T
2026-11-21 09:09:28 +00:00

87 lines
3.4 KiB
Nix

{ config, lib, pkgs, ... }:
{
# Retain the IDs of neuro's former installation; hectic-lab's UID is occupied.
users.users.project-zomboid.uid = 988;
users.groups.project-zomboid.gid = 985;
sops.secrets = {
"project-zomboid/s3-access-key" = {
sopsFile = ../../../sus/neuro-project-zomboid.yaml;
owner = "project-zomboid";
group = "project-zomboid";
};
"project-zomboid/s3-secret-key" = {
sopsFile = ../../../sus/neuro-project-zomboid.yaml;
owner = "project-zomboid";
group = "project-zomboid";
};
};
systemd.services.project-zomboid.preStart = lib.mkBefore ''
password_file=${lib.escapeShellArg "/var/lib/project-zomboid/server-password"}
properties_file=${lib.escapeShellArg "/var/lib/project-zomboid/server-password.ini"}
s3_credentials_file=${lib.escapeShellArg "/var/lib/project-zomboid/s3-credentials"}
s3_credentials_tmp="$(${pkgs.coreutils}/bin/mktemp "''${s3_credentials_file}.XXXXXX")"
trap '${pkgs.coreutils}/bin/rm -f "$s3_credentials_tmp"' EXIT
{
${pkgs.coreutils}/bin/printf 'AWS_ACCESS_KEY_ID='
${pkgs.coreutils}/bin/cat ${lib.escapeShellArg config.sops.secrets."project-zomboid/s3-access-key".path}
${pkgs.coreutils}/bin/printf '\n'
${pkgs.coreutils}/bin/printf 'AWS_SECRET_ACCESS_KEY='
${pkgs.coreutils}/bin/cat ${lib.escapeShellArg config.sops.secrets."project-zomboid/s3-secret-key".path}
${pkgs.coreutils}/bin/printf '\n'
} > "$s3_credentials_tmp"
${pkgs.coreutils}/bin/chmod 0400 "$s3_credentials_tmp"
${pkgs.coreutils}/bin/mv -f "$s3_credentials_tmp" "$s3_credentials_file"
if [ ! -s "$password_file" ] || ! ${pkgs.gnugrep}/bin/grep -Eq '^[0-9a-f]{48}$' "$password_file"; then
umask 077
${pkgs.openssl}/bin/openssl rand -hex 24 > "$password_file"
fi
${pkgs.coreutils}/bin/chmod 0600 "$password_file"
properties_file_tmp="$(${pkgs.coreutils}/bin/mktemp "$(dirname "$properties_file")/.server-password.ini.XXXXXX")"
${pkgs.coreutils}/bin/printf 'Password=%s\n' "$(<"$password_file")" > "$properties_file_tmp"
${pkgs.coreutils}/bin/chmod 0600 "$properties_file_tmp"
${pkgs.coreutils}/bin/mv "$properties_file_tmp" "$properties_file"
'';
hectic.services."project-zomboid" = {
enable = true;
updateOnStart = false;
memory = "4g";
serverName = "servertest";
port = 36565;
udpPort = 36566;
serverPropertiesFile = /var/lib/project-zomboid/server-password.ini;
rcon.enable = true;
# These snapshots retain live settings, world identities and mod options.
serverProperties = builtins.fromJSON (builtins.readFile ./project-zomboid-server.json) // {
server_browser_announced_ip = "95.31.254.84";
};
sandboxProperties = builtins.fromJSON (builtins.readFile ./project-zomboid-sandbox.json);
# Keep the migrated LuaDigitalWatchUI 1.0 and RC_RealisticColdMod 2.2.0
# in Zomboid/mods; Workshop would replace the latter on first startup.
workshopItems = [ ];
mods = [
"\\LuaDigitalWatchUI"
"\\RC_RealisticColdMod"
];
backup = {
enable = true;
onCalendar = "*:0/30";
retentionDays = 0;
s3 = {
enable = true;
bucket = "backup-hectic-lab";
endpoint = "https://hel1.your-objectstorage.com";
region = "hel1";
credentialsFile = "/var/lib/project-zomboid/s3-credentials";
};
};
};
}