From 06e84b79b4be8c684bd568b8294baccf9b14d8b1 Mon Sep 17 00:00:00 2001 From: gabriel-doriath-dohler Date: Sat, 13 Nov 2021 01:52:04 +0100 Subject: [PATCH] add minecraft server to public-cof --- machines/public-cof/configuration.nix | 6 +- machines/public-cof/minecraft.nix | 84 +++++++++++++++++++++++++++ 2 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 machines/public-cof/minecraft.nix diff --git a/machines/public-cof/configuration.nix b/machines/public-cof/configuration.nix index 1556fd3..049bd69 100644 --- a/machines/public-cof/configuration.nix +++ b/machines/public-cof/configuration.nix @@ -1,4 +1,4 @@ -{ config, pkgs, ... }: +{ config, pkgs, lib, ... }: { imports = @@ -9,9 +9,13 @@ ./acme.nix ./networking.nix ./nextcloud.nix + ./minecraft.nix # TODO monitoring ]; + nixpkgs.config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [ + "minecraft-server" + ]; boot.loader.systemd-boot.enable = true; boot.loader.efi.canTouchEfiVariables = true; diff --git a/machines/public-cof/minecraft.nix b/machines/public-cof/minecraft.nix new file mode 100644 index 0000000..0838a64 --- /dev/null +++ b/machines/public-cof/minecraft.nix @@ -0,0 +1,84 @@ +{ lib, pkgs, ... }: +let + papermc = { + ram = 4; # In GB + version = "1.17.1"; + build = 189; + sha256 = "06g2vs8z7k9bl8asjgdz9h8fkd93xam2lbrgmzgamwjp94gvfvrn"; + }; + port = 43000; + rconPort = 25575; +in +{ + # Remote administration + environment.systemPackages = [ pkgs.mcrcon ]; + + # Use papermc + nixpkgs.overlays = [ + (self: super: { + minecraft-server = super.minecraft-server.overrideAttrs (old: { + src = pkgs.fetchurl { + url = with papermc; + "https://papermc.io/api/v2/projects/paper/versions/${version}/builds/${toString build}/downloads/paper-${version}-${toString build}.jar"; + sha256 = papermc.sha256; + }; + }); + }) + ]; + + services.minecraft-server = { + enable = true; + eula = true; + declarative = true; + + jvmOpts = with papermc; + "-Xms${toString ram}G -Xmx${toString ram}G -XX:+UseG1GC -XX:+ParallelRefProcEnabled -XX:MaxGCPauseMillis=200 -XX:+UnlockExperimentalVMOptions -XX:+DisableExplicitGC -XX:+AlwaysPreTouch -XX:G1NewSizePercent=30 -XX:G1MaxNewSizePercent=40 -XX:G1HeapRegionSize=8M -XX:G1ReservePercent=20 -XX:G1HeapWastePercent=5 -XX:G1MixedGCCountTarget=4 -XX:InitiatingHeapOccupancyPercent=15 -XX:G1MixedGCLiveThresholdPercent=90 -XX:G1RSetUpdatingPauseTimePercent=5 -XX:SurvivorRatio=32 -XX:+PerfDisableSharedMem -XX:MaxTenuringThreshold=1"; + + # To get the uuids: https://mcuuid.net/ + whitelist = { + gabriel_dr_dl = "53fced49-da51-4c82-b1d0-37168029db08"; + aimie_dodo = "d10be020-a612-47e5-b0d0-938b9a7eb58e"; + }; + + serverProperties = { + server-port = port; + difficulty = "normal"; + gamemode = "survival"; + max-players = 42; + motd = "This is a test and it will break"; + + view-distance = 7; + + # Map settings + level-seed = "9058136630944956755"; + level-name = "Public COF"; + + level-type = "default"; + spawn-animals = true; + spawn-monsters = true; + spawn-npcs = true; + generate-structures = true; + + enable-command-block = false; + + # Whitelist + white-list = true; + enforce-whitelist = true; + + # Admin + enable-rcon = true; + "rcon.password" = + ''yQZ>O.%]fB{'E.X=HI1/En~i-''; # TODO Warning: it is written in clear in /var/lib/... with read permissions and mcrcom will transmit it without encryption + "rcon.port" = rconPort; + admin-slot = true; + + snoop-enabled = false; + public = false; + + # enable-jmx-monitoring = true; # https://docs.oracle.com/javase/8/docs/technotes/guides/management/agent.html + }; + }; + + networking.firewall.allowedTCPPorts = [ port ]; + networking.firewall.allowedUDPPorts = [ port ]; +}