90 lines
2.2 KiB
Nix
90 lines
2.2 KiB
Nix
{
|
|
config,
|
|
lib,
|
|
pkgs,
|
|
...
|
|
}:
|
|
{
|
|
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.";
|
|
};
|
|
|
|
passwordFile = lib.mkOption {
|
|
type = lib.types.path;
|
|
description = "Runtime file containing the Valheim server password.";
|
|
};
|
|
|
|
};
|
|
|
|
config = lib.mkIf config.modules.services.games.valheim.enable (
|
|
let
|
|
service = config.modules.services.games.valheim;
|
|
startScript = pkgs.writeShellScript "valheim-start" ''
|
|
set -eu
|
|
|
|
password="$(${lib.getExe' pkgs.coreutils "tr"} -d '\n' < ${lib.escapeShellArg service.passwordFile})"
|
|
exec ./valheim_server.x86_64 "$@" -password "$password"
|
|
'';
|
|
in
|
|
{
|
|
modules.services.steamcmd = {
|
|
enable = true;
|
|
inherit (service) steamDir installDir stateDir;
|
|
serviceName = "valheim";
|
|
appId = 896660;
|
|
executable = "${startScript}";
|
|
arguments = [
|
|
"-nographics"
|
|
"-batchmode"
|
|
"-name"
|
|
service.serverName
|
|
"-port"
|
|
(toString service.port)
|
|
"-world"
|
|
service.serverName
|
|
"-savedir"
|
|
service.stateDir
|
|
"-public"
|
|
"0"
|
|
"-modifier"
|
|
"raids"
|
|
"none"
|
|
];
|
|
udpPorts = [
|
|
service.port
|
|
(service.port + 1)
|
|
];
|
|
};
|
|
}
|
|
);
|
|
}
|