{ config, lib, ... }: { options.modules.services.games.valheim = { enable = lib.mkEnableOption "Valheim 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/valheim/main"; description = "Directory where SteamCMD installs the Valheim server files."; }; stateDir = lib.mkOption { type = lib.types.str; example = "/data/state/valheim/main"; description = "Directory where Valheim stores world data."; }; serverName = lib.mkOption { type = lib.types.str; default = "valheim"; description = "Name shown for the Valheim server."; }; port = lib.mkOption { type = lib.types.port; default = 2456; description = "Base UDP port for the Valheim server."; }; password = lib.mkOption { type = lib.types.str; description = "Valheim server password."; }; }; config = lib.mkIf config.modules.services.games.valheim.enable ( let service = config.modules.services.games.valheim; in { modules.services.steamcmd = { enable = true; inherit (service) steamDir installDir stateDir; serviceName = "valheim"; appId = 896660; executable = "./valheim_server.x86_64"; arguments = [ "-nographics" "-batchmode" "-name" service.serverName "-port" (toString service.port) "-world" service.serverName "-savedir" service.stateDir "-password" service.password "-public" "0" ]; udpPorts = [ service.port (service.port + 1) ]; }; } ); }