{ 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=172.20.100.1 -cachedir=${statePath}/Zomboid -nosteam ''; }; }; }