{ config, lib, pkgs, inputs, ... }: let cfg = config.homelab.games.minecraft; in { imports = [ inputs.nix-minecraft.nixosModules.minecraft-servers ]; options.homelab.games.minecraft.enable = lib.mkEnableOption "minecraft servers"; config = lib.mkIf cfg.enable { nixpkgs.overlays = [ inputs.nix-minecraft.overlay ]; environment.systemPackages = [ pkgs.packwiz (pkgs.writeShellScriptBin "mcconsole" '' if [ -z "$1" ]; then name="fantasy" else name="$1" fi sudo ${lib.getExe pkgs.tmux} -S "/run/minecraft/$name.sock" attach '') ]; networking.firewall.allowedUDPPorts = [ /*svc*/ 24454 24453 ]; services.minecraft-servers = let fantasy-modpack = pkgs.fetchPackwizModpack { url = "https://git.lucia.garden/fantasy-minecraft-modpack.git/plain/pack.toml"; packHash = "sha256-oSvw+7C+VC4Ao0qvlRvtC2eL0Gqt+juoFE+57uuueCU="; }; in { enable = true; eula = true; openFirewall = true; servers = { vanilla-1_21_1 = { enable = false; package = pkgs.vanillaServers.vanilla-1_21_1; serverProperties = { server-port = 25566; }; }; fantasy = { enable = true; package = pkgs.fabricServers.fabric-1_20_1; symlinks = { "mods" = "${fantasy-modpack}/mods"; "config/additional-additions-config.json" = "${fantasy-modpack}/config/additional-additions-config.json"; "config/fwaystones/config.json5" = "${fantasy-modpack}/config/fwaystones/config.json5"; "config/simplebackup.json5" = "${fantasy-modpack}/config/simplebackup.json5"; }; jvmOpts = "-Xms8192M -Xmx8192M"; serverProperties = { level-seed = "-5424614792051443123"; allow-flight = true; spawn-protection = 0; max-players = 6; server-port = 25565; simulation-distance = 8; view-distance = 12; difficulty = "normal"; # motd = ''\u00a7f-------\u00a7d Fantasy\u00a7f ----------\u00a7r\n\u00a7f--\u00a7c Survival\u00a7f ---\u00a7b Multiplayer\u00a7f --''; motd = ''\u00a7r \u00a7f------------ << \u00a7dlucia\u00a7f.\u00a72garden\u00a7f >> ------------\u00a7r\n\u00a7l \u00a7f--------- << \u00a7cSurvival \u00a7eMultiplayer \u00a7f>> ---------''; }; }; fantasy-testing = { enable = true; package = pkgs.fabricServers.fabric-1_20_1; symlinks = { "mods" = "${fantasy-modpack}/mods"; "config/additional-additions-config.json" = "${fantasy-modpack}/config/additional-additions-config.json"; "config/configurabledespawntimer.json5" = "${fantasy-modpack}/config/configurabledespawntimer.json5"; "config/fwaystones/config.json5" = "${fantasy-modpack}/config/fwaystones/config.json5"; "config/simplebackup.json5" = "${fantasy-modpack}/config/simplebackup.json5"; # Change the voice chat port, if it is the same as another server it will crash "config/voicechat/voicechat-server.properties" = pkgs.writeText "voicechat-config" '' port=24453 bind_address= max_voice_distance=48.0 whisper_distance=24.0 codec=VOIP mtu_size=1024 keep_alive=1000 enable_groups=true voice_host= allow_recording=true spectator_interaction=false spectator_player_possession=false force_voice_chat=false login_timeout=10000 broadcast_range=-1.0 allow_pings=true use_natives=true ''; }; jvmOpts = "-Xms4096M -Xmx4096M"; serverProperties = { level-seed = "-5424614792051443123"; allow-flight = true; spawn-protection = 0; max-players = 4; server-port = 20000; difficulty = "normal"; gamemode = "creative"; motd = ''\u00a7f-------\u00a7d Fantasy\u00a7f ----------\u00a7r\n\u00a7f--\u00a7c Creative\u00a7f ---\u00a7b Multiplayer\u00a7f --''; }; }; }; }; }; }