at 17.09-beta 2.7 kB view raw
1{ config, lib, pkgs, ... }: 2with lib; 3let 4 5 cfg = config.services.ghostOne; 6 ghostUser = "ghostone"; 7 stateDir = "/var/lib/ghost-one"; 8 9in 10{ 11 12 ###### interface 13 14 options = { 15 services.ghostOne = { 16 17 enable = mkOption { 18 default = false; 19 description = "Enable Ghost-One Warcraft3 game hosting server."; 20 }; 21 22 language = mkOption { 23 default = "English"; 24 type = types.enum [ "English" "Spanish" "Russian" "Serbian" "Turkish" ]; 25 description = "The language of bot messages: English, Spanish, Russian, Serbian or Turkish."; 26 }; 27 28 war3path = mkOption { 29 default = ""; 30 description = '' 31 The path to your local Warcraft III directory, which must contain war3.exe, storm.dll, and game.dll. 32 ''; 33 }; 34 35 mappath = mkOption { 36 default = ""; 37 description = '' 38 The path to the directory where you keep your map files. GHost One doesn't require 39 map files but if it has access to them it can send them to players and automatically 40 calculate most map config values. GHost One will search [bot_mappath + map_localpath] 41 for the map file (map_localpath is set in each map's config file). 42 ''; 43 }; 44 45 config = mkOption { 46 default = ""; 47 description = "Extra configuration options."; 48 }; 49 50 }; 51 }; 52 53 ###### implementation 54 55 config = mkIf cfg.enable { 56 57 users.extraUsers = singleton 58 { name = ghostUser; 59 uid = config.ids.uids.ghostone; 60 description = "Ghost One game server user"; 61 home = stateDir; 62 }; 63 64 users.extraGroups = singleton 65 { name = ghostUser; 66 gid = config.ids.gids.ghostone; 67 }; 68 69 services.ghostOne.config = '' 70# bot_log = /dev/stderr 71 bot_language = ${pkgs.ghostOne}/share/ghost-one/languages/${cfg.language}.cfg 72 bot_war3path = ${cfg.war3path} 73 74 bot_mapcfgpath = mapcfgs 75 bot_savegamepath = savegames 76 bot_mappath = ${cfg.mappath} 77 bot_replaypath = replays 78 ''; 79 80 systemd.services."ghost-one" = { 81 wantedBy = [ "multi-user.target" ]; 82 script = '' 83 mkdir -p ${stateDir} 84 cd ${stateDir} 85 chown ${ghostUser}:${ghostUser} . 86 87 mkdir -p mapcfgs 88 chown ${ghostUser}:${ghostUser} mapcfgs 89 90 mkdir -p replays 91 chown ${ghostUser}:${ghostUser} replays 92 93 mkdir -p savegames 94 chown ${ghostUser}:${ghostUser} savegames 95 96 ln -sf ${pkgs.writeText "ghost.cfg" cfg.config} ghost.cfg 97 ln -sf ${pkgs.ghostOne}/share/ghost-one/ip-to-country.csv 98 ${pkgs.su}/bin/su -s ${pkgs.stdenv.shell} ${ghostUser} \ 99 -c "LANG=C ${pkgs.ghostOne}/bin/ghost++" 100 ''; 101 }; 102 103 }; 104 105}