-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnixos-module.nix
176 lines (172 loc) · 5.04 KB
/
nixos-module.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
166
167
168
169
170
171
172
173
174
175
176
{
pkgs,
lib,
stdenvNoCC,
config,
...
}:
with lib;
let
gpkgs = pkgs.callPackage ./default.nix {};
cfg = config.services.garrys-mod;
defaultUser = {
name = "garrys-mod";
group = "garrys-mod";
isSystemUser = true;
createHome = true;
home = cfg.dataDir;
};
in {
options.services.garrys-mod = {
enable = mkEnableOption "Garry's Mod";
dataDir = mkOption {
example = "/var/lib/gmstranded/";
default = "/var/lib/garrys-mod/";
type = types.str;
description = ''
The directory containing the stateful data of the Garry's Mod server.
In a typical steamcmd installation, this would be the `garrysmod` folder.
'';
};
address = mkOption {
example = "127.0.0.1";
default = null;
type = with types; nullOr str;
description = ''
The address to bind the Garry's Mod server to.
(NOTE: srcds_run seems to ignore this completely. Check `netstat` when running.)
'';
};
port = mkOption {
example = 27805;
default = 27015;
type = types.port;
description = ''
The port to bind the Garry's Mod server to.
'';
};
openFirewall = mkOption {
default = false;
type = types.bool;
description = "Opens the given `port` in the firewall.";
};
gamemode = mkOption {
example = "terrortown";
default = "sandbox";
type = types.str;
description = ''
The gamemode to run on the server.
Make sure it's present in `{dataDir}/gamemodes` or downloaded by `workshopCollection`.
'';
};
map = mkOption {
example = "gms_g4p_stargate_v11";
default = "gm_construct";
type = types.str;
description = ''
The map to run on the server.
Make sure it's present in `{dataDir}/maps` or downloaded by `workshopCollection`.
'';
};
workshopCollection = mkOption {
example = 3035416339;
default = null;
type = with types; nullOr int;
description = ''
A workshop collection that srcds_run will download before starting the server.
'';
};
package = mkPackageOption pkgs [ "garrys-mod" "dedicated-server-unwrapped" ] {};
finalPackage = mkOption {
type = with types; package;
default = cfg.package.override { inherit (cfg) extraPaths; };
};
extraPaths = mkOption {
default = [];
example = [
(stdenvNoCC.mkDerivation {
pname = "gmstranded";
version = "19.00.00";
src = fetchFromGitHub {
owner = "TGRCDev";
repo = "GMStranded";
rev = "4bc8f7cf88be1c6965282167f6151e754651777d";
hash = "sha256-6eRWMU75SpgZgYu6bzOSDP0cs879dPgNR8pWqpcGr4A=";
};
buildPhase = ''
mkdir -p $out/garrysmod
cp -Rs $src/gamemodes $src/particles $src/data $out/garrysmod
'';
})
];
type = with types; listOf package;
description = ''
A list of derivations whose contents are linked to the fake srcds dir when the
server is started. Use this to add additional files (maps, gamemodes, scripts, etc.)
to the server without needing a workshop collection.
'';
};
extraArgs = mkOption {
example = {
sv_lan = 1;
hostname = "My Server";
};
default = {};
type = with types; attrs;
description = ''
Additional arguments to pass to `srcds_run`.
'';
};
user = mkOption {
default = "garrys-mod";
type = with types; str;
description = ''
The user account to run the server with.
'';
};
umask = mkOption {
default = "077";
example = "007";
type = with types; str;
description = ''
The `umask` value to run the server with.
'';
};
};
config = mkMerge [
{nixpkgs.overlays = [(final: prev: {garrys-mod = gpkgs;})];}
(mkIf cfg.enable {
systemd.services.garrys-mod = let
serverPkg = cfg.finalPackage;
runWrapper = gpkgs.dedicated-server.override {
dedicated-server-unwrapped = serverPkg;
defaultArgs = {
inherit (cfg) dataDir;
consoleArgs = {
inherit (cfg) port gamemode map;
} // cfg.extraArgs
// (if cfg.address != null then { ip = cfg.address; } else {})
// (if cfg.workshopCollection != null then { host_workshop_collection = cfg.workshopCollection; } else {});
};
};
in {
description = "Garry's Mod dedicated server";
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
serviceConfig = {
Type = "simple";
User = cfg.user;
ExecStart = "${runWrapper}/bin/run-gmod-server";
UMask = cfg.umask;
};
};
users = mkIf (cfg.user == defaultUser.name) {
users.garrys-mod = defaultUser;
groups.garrys-mod = {};
};
networking.firewall = mkIf cfg.openFirewall {
allowedUDPPorts = [ cfg.port ];
};
})
];
}