diff options
author | Kjetil Orbekk <kj@orbekk.com> | 2022-10-26 16:07:15 -0400 |
---|---|---|
committer | Kjetil Orbekk <kj@orbekk.com> | 2022-10-26 16:07:15 -0400 |
commit | 24095fd99ab4f9428b86445c2045f066195124ad (patch) | |
tree | 9df2f336ecea29f08ab9a52f1bbf65ecdc8f9b8a /modules | |
parent | a5829fdeb5240293063b82af0215ab3b5e13c2c6 (diff) |
Zomboid server
Diffstat (limited to 'modules')
-rw-r--r-- | modules/gaming.nix | 8 | ||||
-rw-r--r-- | modules/valheim.nix | 69 | ||||
-rw-r--r-- | modules/zomboid.nix | 55 |
3 files changed, 62 insertions, 70 deletions
diff --git a/modules/gaming.nix b/modules/gaming.nix index 61b089b..dc881d7 100644 --- a/modules/gaming.nix +++ b/modules/gaming.nix @@ -198,7 +198,13 @@ in { # nixpkgs.config.allowBroken = true; nixpkgs.config.allowUnfreePredicate = pkg: - builtins.elem (lib.getName pkg) [ "steam" "steam-original" "steam-runtime" "minecraft-launcher" ]; + builtins.elem (lib.getName pkg) [ + "steam" + "steamcmd" + "steam-original" + "steam-runtime" + "minecraft-launcher" + ]; services.flatpak.enable = true; diff --git a/modules/valheim.nix b/modules/valheim.nix deleted file mode 100644 index f12a894..0000000 --- a/modules/valheim.nix +++ /dev/null @@ -1,69 +0,0 @@ -{ config, lib, pkgs, ... }: - -let - cfg = config.orbekk.valheim-server; - statePath = "/var/lib/${cfg.stateDir}"; -in -{ - options = { - orbekk.valheim-server = { - enable = lib.mkEnableOption "Enable valheim server"; - programDir = lib.mkOption { - type = lib.types.str; - default = null; - }; - stateDir = lib.mkOption { - type = lib.types.str; - default = "valheim"; - }; - statusPort = lib.mkOption { - type = lib.types.int; - default = 12817; - }; - }; - }; - - config = lib.mkIf cfg.enable { - systemd.services.valheim-server = { - description = "Valheim server"; - wantedBy = [ "multi-user.target" ]; - after = [ "network.target" ]; - path = with pkgs; [ steam.run ]; - - serviceConfig = { - DynamicUser = true; - StateDirectory = cfg.stateDir; - KillSignal = "SIGINT"; - }; - - environment = { - HOME = statePath; - }; - - script = '' - cd ${cfg.programDir} - export templdpath=$LD_LIBRARY_PATH - export LD_LIBRARY_PATH=./linux64:$LD_LIBRARY_PATH - export SteamAppId=892970 - steam-run ./valheim_server.x86_64 -name "doomsday" -port 3400 -world "doomsday" -password "$(cat ${statePath}/password.txt)" -savedir ${statePath} -nographics -batchmode - ''; - }; - - systemd.services.valheim-server-prober = { - description = "Collect metrics for valheim-server"; - startAt = "*:0/5"; - path = with pkgs; [ moreutils systemd gnugrep coreutils ]; - script = '' - systemctl show valheim-server | \ - grep -E 'IPIngress|IPEgress|CPUUsage' | \ - tr '=' ' ' | { - while read k v; do - echo "# TYPE $k counter" - echo "systemd_$k{unit=\"valheim-server.service\"} $v"; - done - } | \ - sponge ${config.orbekk.monitoring-server.textFileDir}/valheim_server.prom - ''; - }; - }; -} diff --git a/modules/zomboid.nix b/modules/zomboid.nix new file mode 100644 index 0000000..3f5dd37 --- /dev/null +++ b/modules/zomboid.nix @@ -0,0 +1,55 @@ +{ config, lib, pkgs, ... }: + +let + cfg = config.orbekk.zomboid-server; + statePath = "/var/lib/${cfg.stateDir}"; + update-zomboid = pkgs.writeText "update-zomboid" '' + // update_zomboid.txt + @ShutdownOnFailedCommand 1 //set to 0 if updating multiple servers at once + @NoPromptForPassword 1 + //force_install_dir /opt/pzserver/ + //for servers which don't need a login + login anonymous + // app_update 380870 validate + app_update 380870 + quit + ''; +in +{ + options = { + orbekk.zomboid-server = { + enable = lib.mkEnableOption "Enable zomboid server"; + stateDir = lib.mkOption { + type = lib.types.str; + default = "zomboid"; + }; + }; + }; + + config = lib.mkIf cfg.enable { + systemd.services.zomboid-server = { + description = "Zomboid server"; + wantedBy = [ "multi-user.target" ]; + after = [ "network.target" ]; + path = with pkgs; [ steam.run ]; + + serviceConfig = { + DynamicUser = true; + StateDirectory = cfg.stateDir; + CacheDirectory = cfg.stateDir; + LogsDirectory = cfg.stateDir; + RuntimeDirectory = cfg.stateDir; + }; + + environment = { + HOME = statePath; + }; + + script = '' + ${pkgs.steamcmd}/bin/steamcmd +runscript ${update-zomboid} + cd $HOME/.local/share/Steam/Steamapps/common/Project\ Zomboid\ Dedicated\ Server + ${pkgs.steam.run}/bin/steam-run ./start-server.sh -adminpassword changeme -ip 0.0.0.0 -cachedir=${statePath}/Zomboid + ''; + }; + }; +} |