2024-04-13 14:26:07 +02:00
|
|
|
{
|
2024-04-20 21:49:15 +02:00
|
|
|
lib,
|
2024-04-20 22:35:55 +02:00
|
|
|
pkgs,
|
2024-04-13 14:26:07 +02:00
|
|
|
config,
|
|
|
|
mkSecret,
|
|
|
|
...
|
2024-04-20 21:49:15 +02:00
|
|
|
}: let
|
2024-04-20 22:35:55 +02:00
|
|
|
inherit (config.virtualisation.oci-containers) backend;
|
|
|
|
|
2024-04-20 21:49:15 +02:00
|
|
|
mkMinecraftServer = name: {
|
|
|
|
port,
|
2024-05-18 12:35:02 +02:00
|
|
|
remotePort,
|
2024-06-27 15:20:19 +02:00
|
|
|
tag ? "java21",
|
2024-04-25 18:14:51 +02:00
|
|
|
dataDir ? "/var/lib/${name}",
|
2024-04-20 21:49:15 +02:00
|
|
|
memory ? "4G",
|
|
|
|
env ? {},
|
2024-06-04 10:59:59 +02:00
|
|
|
extraPorts ? [],
|
2024-04-20 21:49:15 +02:00
|
|
|
}: {
|
|
|
|
virtualisation.oci-containers.containers.${name} = {
|
2024-06-27 15:20:19 +02:00
|
|
|
image = "itzg/minecraft-server:${tag}";
|
2024-06-04 10:59:59 +02:00
|
|
|
ports = ["${builtins.toString port}:25565"] ++ extraPorts;
|
2024-06-27 15:20:19 +02:00
|
|
|
volumes = ["${dataDir}:/data"];
|
2024-04-20 21:49:15 +02:00
|
|
|
environmentFiles = [config.age.secrets.minecraftEnv.path];
|
|
|
|
environment =
|
2024-04-04 21:59:47 +02:00
|
|
|
{
|
2024-04-20 21:49:15 +02:00
|
|
|
EULA = "true";
|
|
|
|
MEMORY = memory;
|
2024-04-04 21:59:47 +02:00
|
|
|
}
|
2024-04-20 21:49:15 +02:00
|
|
|
// env;
|
2024-04-02 20:53:12 +02:00
|
|
|
};
|
2024-04-20 21:49:15 +02:00
|
|
|
|
|
|
|
services.frp.settings.proxies = [
|
|
|
|
{
|
2024-05-18 12:35:02 +02:00
|
|
|
inherit name remotePort;
|
2024-04-20 21:49:15 +02:00
|
|
|
type = "tcp";
|
|
|
|
localIp = "127.0.0.1";
|
|
|
|
localPort = port;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2024-04-20 22:35:55 +02:00
|
|
|
systemd.services."${backend}-${name}".serviceConfig.TimeoutSec = "300";
|
2024-04-02 20:53:12 +02:00
|
|
|
};
|
|
|
|
|
2024-04-20 21:49:15 +02:00
|
|
|
recursiveMerge = attrList:
|
|
|
|
with lib; let
|
|
|
|
f = attrPath:
|
|
|
|
zipAttrsWith (
|
|
|
|
n: values:
|
|
|
|
if tail values == []
|
|
|
|
then head values
|
|
|
|
else if all isList values
|
|
|
|
then unique (concatLists values)
|
|
|
|
else if all isAttrs values
|
|
|
|
then f (attrPath ++ [n]) values
|
|
|
|
else last values
|
|
|
|
);
|
|
|
|
in
|
|
|
|
f [] attrList;
|
|
|
|
|
|
|
|
mkMinecraftServers = attrs: recursiveMerge (lib.mapAttrsToList mkMinecraftServer attrs);
|
|
|
|
in
|
|
|
|
lib.recursiveUpdate {
|
|
|
|
age.secrets = mkSecret "minecraftEnv" {};
|
|
|
|
|
|
|
|
virtualisation.oci-containers.backend = "docker";
|
2024-04-20 22:35:55 +02:00
|
|
|
|
|
|
|
systemd.services.restart-minecraft-servers = {
|
|
|
|
wantedBy = ["multi-user.target"];
|
|
|
|
script = ''
|
|
|
|
${lib.getExe' pkgs.systemd "systemctl"} restart ${backend}-*.service
|
|
|
|
'';
|
|
|
|
serviceConfig.Type = "oneshot";
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.timers.restart-minecraft-servers = {
|
|
|
|
wantedBy = ["timers.target"];
|
|
|
|
timerConfig = {
|
|
|
|
OnCalendar = "*-*-* 05:00:00";
|
|
|
|
Persistent = true;
|
|
|
|
Unit = "restart-minecraft-servers.service";
|
|
|
|
};
|
|
|
|
};
|
2024-04-20 21:49:15 +02:00
|
|
|
}
|
|
|
|
(mkMinecraftServers {
|
2024-06-27 15:20:19 +02:00
|
|
|
atm9 = {
|
|
|
|
port = 25565;
|
|
|
|
remotePort = 6004;
|
|
|
|
tag = "java17";
|
|
|
|
memory = "8G";
|
2024-04-20 21:49:15 +02:00
|
|
|
env = {
|
2024-04-02 20:53:12 +02:00
|
|
|
USE_AIKAR_FLAGS = "true";
|
2024-06-27 15:20:19 +02:00
|
|
|
MOD_PLATFORM = "AUTO_CURSEFORGE";
|
|
|
|
CF_SLUG = "all-the-mods-9";
|
|
|
|
CF_FILE_ID = "5458414";
|
2024-04-02 20:53:12 +02:00
|
|
|
};
|
|
|
|
};
|
2024-04-20 21:49:15 +02:00
|
|
|
|
|
|
|
lynn = {
|
|
|
|
port = 25567;
|
2024-05-18 12:35:02 +02:00
|
|
|
remotePort = 6002;
|
2024-04-20 21:49:15 +02:00
|
|
|
memory = "4G";
|
|
|
|
env = {
|
|
|
|
USE_AIKAR_FLAGS = "true";
|
|
|
|
TYPE = "MODRINTH";
|
2024-05-28 17:19:12 +02:00
|
|
|
MODRINTH_MODPACK = "https://modrinth.com/modpack/adrenaserver/version/1.6.0+1.20.4.fabric";
|
2024-04-20 21:49:15 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
})
|