summaryrefslogtreecommitdiff
path: root/modules/zomboid.nix
blob: e245c8c0a494cab72e920784500f024145a909ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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=172.20.100.1 -cachedir=${statePath}/Zomboid -nosteam
      '';
    };
  };
}