summary refs log tree commit diff
path: root/nixos/modules/services/games/ghost-one.nix
blob: 5762148df2bb17caba2e0de9a4940d4c808c3e71 (plain) (blame)
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
{ config, lib, pkgs, ... }:
with lib;
let

  cfg = config.services.ghostOne;
  ghostUser = "ghostone";
  stateDir = "/var/lib/ghost-one";

in
{

  ###### interface

  options = {
    services.ghostOne = {

      enable = mkOption {
        default = false;
        description = "Enable Ghost-One Warcraft3 game hosting server.";
      };

      language = mkOption {
        default = "English";
        type = types.addCheck types.str
          (lang: elem lang [ "English" "Spanish" "Russian" "Serbian" "Turkish" ]);
        description = "The language of bot messages: English, Spanish, Russian, Serbian or Turkish.";
      };

      war3path = mkOption {
        default = "";
        description = ''
          The path to your local Warcraft III directory, which must contain war3.exe, storm.dll, and game.dll.
        '';
      };

      mappath = mkOption {
        default = "";
        description = ''
          The path to the directory where you keep your map files. GHost One doesn't require
          map files but if it has access to them it can send them to players and automatically
          calculate most map config values. GHost One will search [bot_mappath + map_localpath]
          for the map file (map_localpath is set in each map's config file).
        '';
      };

      config = mkOption {
        default = "";
        description = "Extra configuration options.";
      };

    };
  };

  ###### implementation

  config = mkIf cfg.enable {

    users.extraUsers = singleton
      { name = ghostUser;
        uid = config.ids.uids.ghostone;
        description = "Ghost One game server user";
        home = stateDir;
      };

    users.extraGroups = singleton
      { name = ghostUser;
        gid = config.ids.gids.ghostone;
      };

    services.ghostOne.config = ''
#      bot_log = /dev/stderr
      bot_language = ${pkgs.ghostOne}/share/ghost-one/languages/${cfg.language}.cfg
      bot_war3path = ${cfg.war3path}

      bot_mapcfgpath = mapcfgs
      bot_savegamepath = savegames
      bot_mappath = ${cfg.mappath}
      bot_replaypath = replays
    '';

    systemd.services."ghost-one" = {
      wantedBy = [ "multi-user.target" ];
      script = ''
        mkdir -p ${stateDir}
        cd ${stateDir}
        chown ${ghostUser}:${ghostUser} .

        mkdir -p mapcfgs
        chown ${ghostUser}:${ghostUser} mapcfgs

        mkdir -p replays
        chown ${ghostUser}:${ghostUser} replays

        mkdir -p savegames
        chown ${ghostUser}:${ghostUser} savegames

        ln -sf ${pkgs.writeText "ghost.cfg" cfg.config} ghost.cfg
        ln -sf ${pkgs.ghostOne}/share/ghost-one/ip-to-country.csv
        ${pkgs.su}/bin/su -s ${pkgs.stdenv.shell} ${ghostUser} \
          -c "LANG=C ${pkgs.ghostOne}/bin/ghost++"
      '';
    };

  };

}