{ config, lib, ... }: let cfg = config.guests.valheim; steamDir = "/data/steamcmd"; installDir = "/data/server"; stateDir = "/data/state"; in { options.guests.valheim = { steamPath = lib.mkOption { type = lib.types.nullOr lib.types.str; default = null; example = "/srv/steamcmd"; description = "Host path bind-mounted as SteamCMD's metadata directory."; }; installPath = lib.mkOption { type = lib.types.nullOr lib.types.str; default = null; example = "/srv/valheim/server"; description = "Host path bind-mounted as Valheim's server install directory."; }; statePath = lib.mkOption { type = lib.types.nullOr lib.types.str; default = null; example = "/srv/valheim/state"; description = "Host path bind-mounted as Valheim's world state directory."; }; 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 cfg.enable { assertions = [ { assertion = cfg.steamPath != null; message = "guests.valheim.steamPath must point at the host directory that stores SteamCMD metadata."; } { assertion = cfg.installPath != null; message = "guests.valheim.installPath must point at the host directory that stores Valheim server files."; } { assertion = cfg.statePath != null; message = "guests.valheim.statePath must point at the host directory that stores Valheim world state."; } ]; guests.valheim = { interior.modules.services.games.valheim = { enable = true; inherit (cfg) serverName port password; inherit steamDir installDir stateDir; }; mounts = { ${steamDir} = { directory = cfg.steamPath; owner = config.registry."stable-uid".${config.networking.hostName}.steamcmd; group = "storage"; mode = "0770"; }; ${installDir} = { directory = cfg.installPath; owner = config.registry."stable-uid".${config.networking.hostName}.steamcmd; group = "storage"; mode = "0770"; }; ${stateDir} = { directory = cfg.statePath; owner = config.registry."stable-uid".${config.networking.hostName}.steamcmd; group = "storage"; mode = "0770"; }; }; limits = { memory = lib.mkDefault "4G"; cpu = lib.mkDefault "400%"; tasksMax = lib.mkDefault 1024; }; }; }; }