{ config, lib, pkgs, ... }: { options.modules.services.games.palworld = { enable = lib.mkEnableOption "Palworld dedicated server"; steamDir = lib.mkOption { type = lib.types.str; example = "/data/steamcmd"; description = "Directory where SteamCMD stores metadata and cache files."; }; installDir = lib.mkOption { type = lib.types.str; example = "/data/servers/palworld/tracion"; description = "Directory where SteamCMD installs the Palworld server files."; }; stateDir = lib.mkOption { type = lib.types.str; example = "/data/state/palworld/tracion"; description = "Directory where Palworld stores durable server state."; }; serverName = lib.mkOption { type = lib.types.str; default = "palworld"; description = "Name shown for the Palworld server."; }; port = lib.mkOption { type = lib.types.port; default = 8211; description = "UDP port for the Palworld server."; }; publicIP = lib.mkOption { type = lib.types.nullOr lib.types.str; default = null; description = "Public IP address advertised by the Palworld server."; }; maxPlayers = lib.mkOption { type = lib.types.ints.between 1 32; default = 32; description = "Maximum player count for the Palworld server."; }; publicLobby = lib.mkOption { type = lib.types.bool; default = true; description = "Advertise the server in Palworld's public lobby."; }; autoStart = lib.mkOption { type = lib.types.bool; default = true; description = "Start the Palworld server after the guest reaches network readiness."; }; passwordFile = lib.mkOption { type = lib.types.path; description = "Runtime file containing the Palworld server password."; }; adminPasswordFile = lib.mkOption { type = lib.types.path; description = "Runtime file containing the Palworld admin password."; }; }; config = lib.mkIf config.modules.services.games.palworld.enable ( let service = config.modules.services.games.palworld; savedDir = "${service.installDir}/Pal/Saved"; defaultSettingsFile = "${service.installDir}/DefaultPalWorldSettings.ini"; settingsFile = "${savedDir}/Config/LinuxServer/PalWorldSettings.ini"; renderSettingsScript = pkgs.writeText "render-palworld-settings.py" '' import json import os from pathlib import Path import re import sys import tempfile default_path, settings_path, server_name, password_path, admin_password_path = sys.argv[1:] default_path = Path(default_path) settings_path = Path(settings_path) source_path = settings_path if settings_path.exists() else default_path text = source_path.read_text(encoding="utf-8") def read_secret(path): return Path(path).read_text(encoding="utf-8").rstrip("\r\n") def set_string_setting(text, name, value): assignment = f"{name}={json.dumps(value, ensure_ascii=False)}" pattern = re.compile(rf'(?