Skip to content

Commit

Permalink
feat(etna): add mkMinecraftServer function
Browse files Browse the repository at this point in the history
  • Loading branch information
uku3lig committed Apr 20, 2024
1 parent 45be412 commit 54d1033
Showing 1 changed file with 82 additions and 34 deletions.
116 changes: 82 additions & 34 deletions systems/etna/minecraft.nix
Original file line number Diff line number Diff line change
@@ -1,44 +1,82 @@
{
lib,
config,
mkSecret,
...
}: {
age.secrets = mkSecret "minecraftEnv" {};

services.frp = {
enable = true;
role = "client";
settings = {
serverAddr = "49.13.148.129";
serverPort = 7000;

proxies = [
}: let
mkMinecraftServer = name: {
port,
frpPort,
memory ? "4G",
env ? {},
}: {
virtualisation.oci-containers.containers.${name} = {
image = "itzg/minecraft-server";
ports = ["${builtins.toString port}:25565"];
volumes = [
"/data/${name}:/data"
"/data/downloads:/downloads"
];
environmentFiles = [config.age.secrets.minecraftEnv.path];
environment =
{
name = "ragnamod7";
type = "tcp";
localIp = "127.0.0.1";
localPort = 25566;
remotePort = 6001;
EULA = "true";
MEMORY = memory;
}
];
// env;
};

services.frp.settings.proxies = [
{
name = name;
type = "tcp";
localIp = "127.0.0.1";
localPort = port;
remotePort = frpPort;
}
];

systemd.services."${config.virtualisation.oci-containers.backend}-${name}".serviceConfig.TimeoutSec = "300";
};

virtualisation.oci-containers.backend = "docker";
virtualisation.oci-containers.containers = {
"ragnamod7" = {
image = "itzg/minecraft-server";
ports = ["25566:25565"];
volumes = [
"/data/ragnamod7:/data"
"/data/downloads:/downloads"
];
environmentFiles = [
config.age.secrets.minecraftEnv.path
];
environment = {
EULA = "true";
MEMORY = "10G";
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" {};

services.frp = {
enable = true;
role = "client";
settings = {
serverAddr = "49.13.148.129";
serverPort = 7000;
};
};

virtualisation.oci-containers.backend = "docker";
}
(mkMinecraftServers {
ragnamod7 = {
port = 25566;
frpPort = 6001;
memory = "10G";
env = {
USE_AIKAR_FLAGS = "true";
TYPE = "AUTO_CURSEFORGE";
CF_SLUG = "ragnamod-vii";
Expand All @@ -47,5 +85,15 @@
CF_IGNORE_MISSING_FILES = "mods/ftbbackups2-forge-1.18.2-1.0.23.jar";
};
};
};
}

lynn = {
port = 25567;
frpPort = 6002;
memory = "4G";
env = {
USE_AIKAR_FLAGS = "true";
TYPE = "MODRINTH";
MODRINTH_MODPACK = "https://modrinth.com/modpack/adrenaserver/version/1.5.0+1.20.4.fabric";
};
};
})

0 comments on commit 54d1033

Please sign in to comment.