nixos-config/profiles/servers/minecraft.nix

181 lines
5.5 KiB
Nix
Raw Normal View History

2023-07-26 21:19:30 +03:00
{ config, pkgs, lib, inputs, ... }:
let
2024-07-16 15:36:43 +03:00
jdk21 = pkgs.temurin-bin;
jdk17 = pkgs.temurin-bin-17;
2023-07-26 21:19:30 +03:00
jvmOpts = lib.concatStringsSep " " [
"-XX:+UnlockExperimentalVMOptions"
2024-06-19 12:55:04 +03:00
"-XX:+UseZGC"
"-XX:+ZGenerational"
"-XX:-ZUncommit"
"-XX:-ZProactive"
2023-07-26 21:19:30 +03:00
"-XX:+AlwaysPreTouch"
2024-06-19 12:55:04 +03:00
"-XX:+UseTransparentHugePages"
2023-07-26 21:19:30 +03:00
];
rsyncSSHKeys = config.users.users.${config.mainuser}.openssh.authorizedKeys.keys;
defaults = {
allow-flight = true;
difficulty = 2;
# 5 minutes tick timeout, for heavy packs
max-tick-time = 5 * 60 * 1000;
online-mode = false;
spawn-protection = 0;
};
2024-06-19 12:55:04 +03:00
instances = config.services.modded-minecraft-servers.instances;
in
{
imports = [
inputs.mms.module
inputs.ataraxiasjel-nur.nixosModules.rustic
];
2023-07-26 21:19:30 +03:00
services.modded-minecraft-servers = {
eula = true;
instances = {
statech = {
2023-11-11 03:17:51 +03:00
enable = false;
2023-07-26 21:19:30 +03:00
inherit rsyncSSHKeys jvmOpts;
jvmMaxAllocation = "6144m";
2023-09-16 00:54:08 +03:00
jvmInitialAllocation = "6144m";
2024-07-16 15:36:43 +03:00
jvmPackage = jdk17;
2023-07-26 21:19:30 +03:00
serverConfig = defaults // {
2024-07-16 15:36:43 +03:00
server-port = 25567;
rcon-port = 25577;
2023-07-26 21:19:30 +03:00
motd = "StaTech";
max-world-size = 50000;
level-seed = "-4411466874705470064";
};
};
2024-06-19 12:55:04 +03:00
all-of-create = {
2024-06-26 12:35:17 +03:00
enable = false;
inherit rsyncSSHKeys jvmOpts;
jvmMaxAllocation = "4096m";
jvmInitialAllocation = "4096m";
2024-07-16 15:36:43 +03:00
jvmPackage = jdk21;
2024-06-26 12:35:17 +03:00
serverConfig = defaults // {
2024-07-16 15:36:43 +03:00
server-port = 25566;
2024-06-26 12:35:17 +03:00
rcon-port = 25576;
motd = "All of Create";
max-world-size = 50000;
level-seed = "-6893059259197159072";
};
};
create = {
2024-06-19 12:55:04 +03:00
enable = true;
inherit rsyncSSHKeys jvmOpts;
jvmMaxAllocation = "4096m";
jvmInitialAllocation = "4096m";
2024-07-16 15:36:43 +03:00
jvmPackage = jdk21;
2024-06-19 12:55:04 +03:00
serverConfig = defaults // {
server-port = 25565;
2024-07-16 15:36:43 +03:00
rcon-port = 25575;
2024-06-26 12:35:17 +03:00
motd = "AtaraxiaSjel's Create";
2024-06-19 12:55:04 +03:00
max-world-size = 50000;
2024-07-16 15:36:43 +03:00
# 520 120 375
level-seed = "-9219784036026610404";
2024-06-19 12:55:04 +03:00
};
};
2023-07-26 21:19:30 +03:00
};
};
2024-06-19 12:55:04 +03:00
persist.state.directories = map (x: "/var/lib/mc-${x}") (lib.attrNames instances);
2023-07-26 21:19:30 +03:00
2024-06-19 12:55:04 +03:00
# Rustic backup for all servers, including disabled ones
sops.secrets.rustic-workstation-pass.sopsFile = inputs.self.secretsDir + /rustic.yaml;
sops.secrets.rustic-minecraft-s3-env.sopsFile = inputs.self.secretsDir + /rustic.yaml;
services.rustic.backups = rec {
workstation-minecraft-backup = {
backup = true;
prune = false;
initialize = false;
2024-07-16 15:36:43 +03:00
# environmentFile = config.sops.secrets.rustic-minecraft-s3-env.path;
2024-06-19 12:55:04 +03:00
pruneOpts = [ "--repack-cacheable-only=false" ];
timerConfig = {
OnCalendar = "*:0/15";
};
backupPrepareCommand = ''
start_backup=false
${lib.strings.concatLines (
map (x: "systemctl is-active --quiet mc-${x}.service && start_backup=true") (
lib.attrNames instances
)
)}
if [ "$start_backup" = false ]; then
echo "No Minecraft servers are running. Skip backup."
exit 1
fi
${lib.strings.concatLines (
map (x: ''
if systemctl is-active --quiet mc-${x}.service; then
export MCRCON_PORT=${toString instances.${x}.serverConfig.rcon-port}
export MCRCON_PASS=${instances.${x}.serverConfig.rcon-password}
${pkgs.mcrcon}/bin/mcrcon "say Rustic backup is started!" save-off "save-all"
fi
'') (lib.attrNames instances)
)}
sleep 3
'';
backupCleanupCommand = ''
${lib.strings.concatLines (
map (x: ''
if systemctl is-active --quiet mc-${x}.service; then
export MCRCON_PORT=${toString instances.${x}.serverConfig.rcon-port}
export MCRCON_PASS=${instances.${x}.serverConfig.rcon-password}
${pkgs.mcrcon}/bin/mcrcon "say Rustic backup is done!" save-on
fi
'') (lib.attrNames instances)
)}
'';
settings = let
label = "workstation-minecraft";
in {
repository = {
2024-07-16 15:36:43 +03:00
# repository = "opendal:s3";
repository = "/persist/backup/minecraft-servers";
2024-06-19 12:55:04 +03:00
password-file = config.sops.secrets.rustic-workstation-pass.path;
2024-07-16 15:36:43 +03:00
no-cache = true;
# options = {
# root = label;
# bucket = "rustic-backups";
# region = "us-east-1";
# endpoint = "https://s3.ataraxiadev.com";
# };
2024-06-19 12:55:04 +03:00
};
backup = {
host = config.device;
label = label;
ignore-devid = true;
group-by = "label";
skip-identical-parent = true;
2024-11-12 01:00:07 +03:00
globs = [ "!/var/lib/**/backups" "!/var/lib/**/.cache" "!/var/lib/**/logs" ];
2024-07-16 15:36:43 +03:00
exclude-if-present = [ ".nobackup" "CACHEDIR.TAG" ];
2024-11-12 01:00:07 +03:00
snapshots = [{
sources = map (x: "/var/lib/mc-${x}") (lib.attrNames instances);
2024-06-19 12:55:04 +03:00
}];
};
forget = {
2024-11-12 01:00:07 +03:00
filter-labels = [ label ];
2024-06-19 12:55:04 +03:00
group-by = "label";
prune = true;
keep-hourly = 6;
keep-daily = 2;
keep-weekly = 1;
keep-monthly = 0;
};
};
};
workstation-minecraft-prune = workstation-minecraft-backup // {
backup = false;
prune = true;
createWrapper = false;
backupPrepareCommand = null;
backupCleanupCommand = null;
timerConfig = {
OnCalendar = "hourly";
Persistent = true;
};
};
};
2023-07-26 21:19:30 +03:00
}