-
Notifications
You must be signed in to change notification settings - Fork 21
/
nixcon-garnix-player-module.nix
97 lines (84 loc) · 2.23 KB
/
nixcon-garnix-player-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
{
config,
lib,
pkgs,
...
}:
let
cfg = config.playerConfig;
in
{
options.playerConfig = {
githubLogin = lib.mkOption {
type = lib.types.str;
description = "The github user/organization to use for the player";
};
githubRepo = lib.mkOption {
type = lib.types.str;
description = "The github repository to use for the player";
};
sshKey = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
description = "The ssh public key to add to the `me` authorized keys";
};
webserver = lib.mkOption {
type = lib.types.package;
description = "The webserver package to run";
};
gameServerUrl = lib.mkOption {
type = lib.types.str;
description = "The url of the game server";
default = "https://game-server.main.nixcon-2024-game-server.garnix-io.garnix.me";
};
};
config = {
systemd.services.webserver = {
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
description = "The player webserver service";
script = lib.getExe cfg.webserver;
environment = {
PORT = "8080";
};
serviceConfig = {
DynamicUser = true;
ExecStartPre = "${lib.getExe pkgs.curl} -v --retry 10 --retry-delay 0 --retry-all-errors --fail -X POST ${cfg.gameServerUrl}/register/${cfg.githubLogin}/${cfg.githubRepo}";
};
};
services.nginx = {
enable = true;
virtualHosts = {
"default" = {
default = true;
locations."/".proxyPass = "http://127.0.0.1:8080";
};
};
};
users.users.me = {
isNormalUser = true;
description = "me";
extraGroups = [
"wheel"
"systemd-journal"
];
openssh.authorizedKeys.keys =
if cfg.sshKey == null
then []
else [ cfg.sshKey ];
};
garnix.server.enable = true;
services.openssh.enable = true;
security.sudo = {
enable = true;
execWheelOnly = true;
wheelNeedsPassword = false;
};
networking = {
hostName = "player";
firewall.allowedTCPPorts = [ 80 ];
};
virtualisation.vmVariant.services.getty.autologinUser = "me";
system.stateVersion = "24.11";
};
}