2023-09-17 19:51:08 +00:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
pkgs,
|
|
|
|
lib,
|
|
|
|
inputs,
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
with lib; let
|
|
|
|
cfg = config.services.skynet_games_minecraft;
|
|
|
|
|
|
|
|
# got tired of how long this is so I created a var for it.
|
|
|
|
short_domain = "${cfg.domain.sub}.${cfg.domain.base}.${cfg.domain.tld}";
|
|
|
|
in {
|
2023-04-27 00:47:17 +00:00
|
|
|
imports = [
|
2023-05-24 15:39:02 +00:00
|
|
|
../acme.nix
|
2023-05-24 15:52:18 +00:00
|
|
|
../dns.nix
|
|
|
|
../firewall.nix
|
2023-05-24 15:39:02 +00:00
|
|
|
../nginx.nix
|
2023-07-21 20:56:19 +00:00
|
|
|
inputs.arion.nixosModules.arion
|
2023-05-24 15:39:02 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
options.services.skynet_games_minecraft = {
|
|
|
|
enable = mkEnableOption "Skynet Games Minecraft";
|
|
|
|
|
|
|
|
host = {
|
|
|
|
ip = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
};
|
|
|
|
|
|
|
|
name = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
domain = {
|
|
|
|
tld = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "ie";
|
|
|
|
};
|
|
|
|
|
|
|
|
base = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "skynet";
|
|
|
|
};
|
|
|
|
|
|
|
|
sub = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "minecraft.games";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
skynet_firewall.forward = [
|
|
|
|
"ip daddr ${cfg.host.ip} tcp dport 80 counter packets 0 bytes 0 accept"
|
|
|
|
"ip daddr ${cfg.host.ip} tcp dport 443 counter packets 0 bytes 0 accept"
|
|
|
|
"ip daddr ${cfg.host.ip} tcp dport 25565 counter packets 0 bytes 0 accept"
|
2023-04-27 00:47:17 +00:00
|
|
|
];
|
|
|
|
|
2023-08-06 19:09:15 +00:00
|
|
|
skynet_acme.domains = [
|
2023-09-17 19:51:08 +00:00
|
|
|
"${cfg.domain.sub}.${cfg.domain.base}.${cfg.domain.tld}"
|
2023-08-06 19:53:04 +00:00
|
|
|
"*.${cfg.domain.sub}.${cfg.domain.base}.${cfg.domain.tld}"
|
2023-08-06 19:09:15 +00:00
|
|
|
];
|
|
|
|
|
2023-07-16 00:53:21 +00:00
|
|
|
skynet_dns.records = [
|
|
|
|
# the minecraft (web) config server
|
2023-09-17 19:51:08 +00:00
|
|
|
{
|
|
|
|
record = "config.${cfg.domain.sub}";
|
|
|
|
r_type = "CNAME";
|
|
|
|
value = cfg.host.name;
|
|
|
|
}
|
2023-06-11 21:11:57 +00:00
|
|
|
|
2023-07-16 00:53:21 +00:00
|
|
|
# our own minecraft hosts
|
2023-09-17 19:51:08 +00:00
|
|
|
{
|
|
|
|
record = "compsoc_classic.${cfg.domain.sub}";
|
|
|
|
r_type = "CNAME";
|
|
|
|
value = cfg.host.name;
|
|
|
|
}
|
|
|
|
{
|
|
|
|
record = "compsoc.${cfg.domain.sub}";
|
|
|
|
r_type = "CNAME";
|
|
|
|
value = cfg.host.name;
|
|
|
|
}
|
2023-05-24 15:39:02 +00:00
|
|
|
|
2023-07-16 00:53:21 +00:00
|
|
|
# gsoc servers
|
2023-09-17 19:51:08 +00:00
|
|
|
{
|
|
|
|
record = "gsoc.${cfg.domain.sub}";
|
|
|
|
r_type = "CNAME";
|
|
|
|
value = cfg.host.name;
|
|
|
|
}
|
|
|
|
{
|
|
|
|
record = "gsoc_abridged.${cfg.domain.sub}";
|
|
|
|
r_type = "CNAME";
|
|
|
|
value = cfg.host.name;
|
|
|
|
}
|
2023-07-16 00:53:21 +00:00
|
|
|
];
|
2023-04-25 23:24:54 +00:00
|
|
|
|
2023-05-24 15:39:02 +00:00
|
|
|
networking.firewall.allowedTCPPorts = [
|
|
|
|
# for the proxy
|
|
|
|
25565
|
2023-06-11 21:11:57 +00:00
|
|
|
];
|
2023-04-27 00:47:17 +00:00
|
|
|
|
2023-06-11 21:11:57 +00:00
|
|
|
services.nginx.virtualHosts = {
|
|
|
|
# https://config.minecraft.games.skynet.ie
|
|
|
|
"config.${short_domain}" = {
|
|
|
|
forceSSL = true;
|
|
|
|
useACMEHost = "skynet";
|
|
|
|
locations."/" = {
|
|
|
|
proxyPass = "https://localhost:8443";
|
|
|
|
proxyWebsockets = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
# https://compsoc_classic.minecraft.games.skynet.ie/map/
|
|
|
|
"compsoc_classic.${short_domain}" = {
|
|
|
|
forceSSL = true;
|
|
|
|
useACMEHost = "skynet";
|
|
|
|
locations."/map/".alias = "/etc/games/minecraft/craftycontrol/servers/f4c5eb33-c6d6-421c-81ab-ded31f6e8750/plugins/dynmap/web/";
|
|
|
|
};
|
2023-05-24 15:39:02 +00:00
|
|
|
};
|
2023-04-26 00:52:47 +00:00
|
|
|
|
2023-05-24 15:39:02 +00:00
|
|
|
# arion is one way to use docker on nixos
|
|
|
|
# see https://gitlab.com/c2842/computer_society/nixos/-/blob/733b867f4782afa795848135a83e97a5cafaf16a/applications/games/minecraft.nix
|
|
|
|
# for an example of a single compose file with multiple services
|
|
|
|
virtualisation.arion = {
|
|
|
|
backend = "docker";
|
|
|
|
projects = {
|
2023-06-11 21:11:57 +00:00
|
|
|
minecraft.settings.services = {
|
|
|
|
mc_proxy.service = {
|
|
|
|
image = "itzg/mc-router:1.18.0";
|
2023-09-17 19:51:08 +00:00
|
|
|
ports = ["25565:25565/tcp"];
|
|
|
|
expose = ["25565"];
|
2023-06-11 21:11:57 +00:00
|
|
|
command = [
|
2023-06-25 20:29:27 +00:00
|
|
|
"--mapping=compsoc_classic.${short_domain}=mc_config:20000,compsoc.${short_domain}=mc_config:20001,gsoc.${short_domain}=mc_config:20002,gsoc.${short_domain}=mc_config:20002,gsoc_abridged.${short_domain}=mc_config:20003"
|
2023-06-11 21:11:57 +00:00
|
|
|
];
|
|
|
|
};
|
|
|
|
|
|
|
|
mc_config.service = {
|
|
|
|
image = "registry.gitlab.com/crafty-controller/crafty-4:4.1.1";
|
2023-04-25 23:24:54 +00:00
|
|
|
|
2023-05-24 15:39:02 +00:00
|
|
|
environment = {
|
2023-09-17 19:51:08 +00:00
|
|
|
TZ = "Etc/UTC";
|
2023-05-24 15:39:02 +00:00
|
|
|
};
|
2023-04-27 00:47:17 +00:00
|
|
|
|
2023-06-11 21:11:57 +00:00
|
|
|
volumes = [
|
|
|
|
"/etc/games/minecraft/craftycontrol/backups:/crafty/backups"
|
|
|
|
"/etc/games/minecraft/craftycontrol/logs:/crafty/logs"
|
|
|
|
"/etc/games/minecraft/craftycontrol/servers:/crafty/servers"
|
|
|
|
"/etc/games/minecraft/craftycontrol/config:/crafty/app/config"
|
|
|
|
"/etc/games/minecraft/craftycontrol/import:/crafty/import"
|
|
|
|
];
|
2023-05-24 15:39:02 +00:00
|
|
|
|
|
|
|
ports = [
|
2023-06-11 21:11:57 +00:00
|
|
|
# this ius https only
|
|
|
|
"8443:8443/tcp"
|
|
|
|
# compsoc classic
|
|
|
|
"20000:20000/tcp"
|
|
|
|
# compsoc
|
|
|
|
"20001:20001/tcp"
|
|
|
|
# games
|
|
|
|
"20002:20002/tcp"
|
2023-05-24 15:39:02 +00:00
|
|
|
];
|
2023-04-25 23:24:54 +00:00
|
|
|
};
|
2023-04-26 01:01:29 +00:00
|
|
|
};
|
2023-04-25 23:24:54 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2023-09-17 19:51:08 +00:00
|
|
|
}
|