forked from tgstation/tgstation-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtgstation-server.nix
165 lines (146 loc) · 4.81 KB
/
tgstation-server.nix
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
inputs@{
config,
lib,
nixpkgs,
pkgs,
writeShellScriptBin,
...
}:
let
pkgs-i686 = nixpkgs.legacyPackages.i686-linux;
cfg = config.services.tgstation-server;
package = import ./package.nix inputs;
stdenv = pkgs-i686.stdenv_32bit;
rpath = pkgs-i686.lib.makeLibraryPath [
stdenv.cc.cc.lib
];
byond-patcher = pkgs-i686.writeShellScriptBin "EngineInstallComplete-050-TgsPatchELFByond.sh" ''
# If the file doesn't exist, assume OD
if [[ ! -f ../../Byond/$1/byond/bin/DreamDaemon ]] ; then
echo "DreamDaemon doesn't appear to exist. Assuming OD install"
exit
fi
BYOND_PATH=$(realpath ../../Byond/$1/byond/bin/)
${pkgs.patchelf}/bin/patchelf --set-interpreter "$(cat ${stdenv.cc}/nix-support/dynamic-linker)" \
--set-rpath "$BYOND_PATH:${rpath}" \
$BYOND_PATH/{DreamDaemon,DreamDownload,DreamMaker}
'';
tgs-wrapper = pkgs.writeShellScriptBin "tgs-path-wrapper" ''
export PATH=$PATH:${cfg.extra-path}
exec ${package}/bin/tgstation-server --appsettings-base-path=/etc/tgstation-server.d --General:SetupWizardMode=Never --General:AdditionalEventScriptsDirectories:0=/etc/tgstation-server.d/EventScripts --General:AdditionalEventScriptsDirectories:1=${byond-patcher}/bin
'';
in
{
##### interface. here we define the options that users of our service can specify
options = {
# the options for our service will be located under services.foo
services.tgstation-server = {
enable = lib.mkOption {
type = lib.types.bool;
default = false;
description = ''
Whether to enable tgstation-server.
'';
};
username = lib.mkOption {
type = lib.types.str;
default = "tgstation-server";
description = ''
The name of the user used to execute tgstation-server.
'';
};
groupname = lib.mkOption {
type = lib.types.str;
default = "tgstation-server";
description = ''
The name of group the user used to execute tgstation-server will belong to.
'';
};
home-directory = lib.mkOption {
type = lib.types.str;
default = "/home/tgstation-server";
description = ''
The home directory of TGS. Should be persistent.
'';
};
production-appsettings = lib.mkOption {
type = lib.types.path;
default = '''';
description = ''
A formatted appsettings.Production.yml file.
'';
};
extra-path = lib.mkOption {
type = lib.types.str;
default = "";
description = ''
Extra PATH entries to add to the TGS process
'';
};
environmentFile = lib.mkOption {
type = lib.types.nullOr lib.types.path;
default = null;
description = ''
Environment file as defined in {manpage}`systemd.exec(5)`
'';
};
};
};
config = lib.mkIf cfg.enable {
users.groups."${cfg.groupname}" = { };
users.users."${cfg.username}" = {
isSystemUser = true;
createHome = true;
group = cfg.groupname;
home = cfg.home-directory;
};
environment.etc = {
"tgstation-server.d/appsettings.yml" = {
text = (builtins.readFile "${package}/bin/appsettings.yml");
group = cfg.groupname;
mode = "0644";
};
"tgstation-server.d/appsettings.Production.yml" = {
source = cfg.production-appsettings;
group = cfg.groupname;
mode = "0640";
};
"tgstation-server.d/EventScripts/README.txt" = {
text = "TGS event scripts placed here will be executed by all online instances";
group = cfg.groupname;
mode = "0640";
};
};
systemd.services.tgstation-server = {
description = "tgstation-server";
serviceConfig = {
EnvironmentFile = lib.mkIf (cfg.environmentFile != null) cfg.environmentFile;
User = cfg.username;
Type = "notify-reload";
NotifyAccess = "all";
WorkingDirectory = "${package}/bin";
ExecStart = "${tgs-wrapper}/bin/tgs-path-wrapper";
Restart = "always";
KillMode = "process";
ReloadSignal = "SIGUSR2";
AmbientCapabilities = "CAP_SYS_NICE CAP_SYS_PTRACE";
WatchdogSec = "60";
WatchdogSignal = "SIGTERM";
LogsDirectory = "tgstation-server";
};
reloadTriggers = [
(lib.mkIf (cfg.environmentFile != null) [ cfg.environmentFile ])
"/etc/tgstation.server.d/appsettings.Production.yml"
];
restartIfChanged = false; # So that the TGS service doesn't just get restarted whenever it's updated, and boots players
wantedBy = [ "multi-user.target" ];
after = [
"network.target"
"mysql.service"
"mariadb.service"
"postgresql.service"
"mssql-server.service"
];
};
};
}