commit fd42ae32c6113fc303fa35668a5e83e23e41d223
parent e944cd0130920993e257a64e20ab1106bfa7a293
Author: Leah (ctucx) <git@ctu.cx>
Date: Tue, 2 Jul 2024 17:47:59 +0200
parent e944cd0130920993e257a64e20ab1106bfa7a293
Author: Leah (ctucx) <git@ctu.cx>
Date: Tue, 2 Jul 2024 17:47:59 +0200
machines/trabbi: add minecraft-bedrock-server
7 files changed, 202 insertions(+), 13 deletions(-)
A
|
109
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
diff --git a/machines/briefkasten/smarthome/mqtt-webui/default.nix b/machines/briefkasten/smarthome/mqtt-webui/default.nix @@ -7,7 +7,7 @@ let in { # dns.zones."ctu.cx".subdomains."smart.home".CNAME = [ "${config.networking.fqdn}." ]; - services.dnsmasq.settings.cname = [ "smart.home.ctu.cx, ${config.networking.fqdn}" ]; + services.dnsmasq.settings.cname = [ "smart.home.ctu.cx, home.ctu.cx" ]; services = {
diff --git a/machines/trabbi/default.nix b/machines/trabbi/default.nix @@ -26,6 +26,9 @@ ./matrix ./mail + + ./minecraft-bedrock-server.nix + ./websites ./grocy.nix ./travelynx2fedi.nix
diff --git a/machines/trabbi/minecraft-bedrock-server.nix b/machines/trabbi/minecraft-bedrock-server.nix @@ -0,0 +1,39 @@ +{ config, ... }: + +{ + + services.minecraft-bedrock-server = { + enable = true; + permissions = [ + { + permission = "operator"; + name = "ctucx"; + xuid = 2535444994578292; + } + ]; + allowList = [ + { + ignoresPlayerLimit = false; + name = "ctucx"; + xuid = 2535444994578292; + } + { + ignoresPlayerLimit = false; + name = "meuchelkatze"; + xuid = 2535458079124878; + } + ]; + settings = { + enable-lan-visibility = false; + server-name = "ctucx.bedrock-server"; + allow-list = true; + allow-cheats = true; + online-mode = true; + }; + }; + + networking.firewall.allowedUDPPorts = [ + 19132 19133 + ]; + +}+ \ No newline at end of file
diff --git a/modules/default.nix b/modules/default.nix @@ -18,6 +18,7 @@ ./linux/dns.nix ./linux/gotosocial.nix ./linux/nginx-sni-proxy.nix + ./linux/minecraft-bedrock-server.nix ] else []) (if (currentSystem == "aarch64-darwin") then [ inputs.agenix.darwinModules.default
diff --git a/modules/linux/minecraft-bedrock-server.nix b/modules/linux/minecraft-bedrock-server.nix @@ -0,0 +1,109 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + cfg = config.services.minecraft-bedrock-server; + + cfgToString = v: if builtins.isBool v then boolToString v else toString v; + allowListFile = pkgs.writeText "allowlist.json" (builtins.toJSON cfg.allowList); + permissionsFile = pkgs.writeText "permissions.json" (builtins.toJSON cfg.permissions); + serverPropertiesFile = pkgs.writeText "server.properties" ('' + # server.properties managed by NixOS configuration + '' + concatStringsSep "\n" (mapAttrsToList + (n: v: "${n}=${cfgToString v}") cfg.settings)); + +in { + + options = { + services.minecraft-bedrock-server = { + + enable = mkOption { + type = types.bool; + default = false; + }; + + dataDir = mkOption { + type = types.path; + default = "/var/lib/minecraft-bedrock"; + }; + + allowList = mkOption { + type = with types; listOf (attrs); + default = []; + }; + + permissions = mkOption { + type = with types; listOf (attrs); + default = []; + }; + + settings = mkOption { + type = with types; attrsOf (oneOf [ bool int str ]); + }; + + package = mkOption { + type = types.package; + default = pkgs.minecraft-bedrock-server; + }; + + }; + }; + + config = mkIf cfg.enable { + + services.minecraft-bedrock-server.settings = { + server-name = lib.mkDefault "Bedrock Server"; + gamemode = lib.mkDefault "survival"; + difficulty = lib.mkDefault "easy"; + allow-list = lib.mkDefault false; + allow-cheats = lib.mkDefault false; + max-players = lib.mkDefault 10; + online-mode = lib.mkDefault false; + server-port = lib.mkDefault 19132; + server-portv6 = lib.mkDefault 19133; + view-distance = lib.mkDefault 32; + tick-distance = lib.mkDefault 4; + player-idle-timeout = lib.mkDefault 30; + max-threads = lib.mkDefault 4; + level-name = lib.mkDefault "Bedrock level"; + level-seed = lib.mkDefault ""; + default-player-permission-level = lib.mkDefault "member"; + texturepack-required = lib.mkDefault false; + content-log-file-enabled = lib.mkDefault false; + compression-threshold = lib.mkDefault 1; + server-authoritative-movement = lib.mkDefault "server-auth"; + correct-player-movement = lib.mkDefault false; + }; + + + users.groups.minecraft = {}; + users.users.minecraft = { + isSystemUser = true; + home = cfg.dataDir; + createHome = true; + group = "minecraft"; + }; + + systemd.services.minecraft-bedrock-server = { + description = "Minecraft Bedrock Server Service"; + wantedBy = [ "multi-user.target" ]; + after = [ "network.target" ]; + + serviceConfig = { + ExecStart = "${cfg.package}/bin/bedrock_server"; + Restart = "always"; + User = "minecraft"; + WorkingDirectory = cfg.dataDir; + }; + + preStart = '' + cp -a -n ${cfg.package}/var/lib/* . + cp -f ${serverPropertiesFile} server.properties + cp -f ${permissionsFile} permissions.json + cp -f ${allowListFile} allowlist.json + chmod +w server.properties + ''; + }; + }; +}
diff --git a/pkgs/minecraft-bedrock-server.nix b/pkgs/minecraft-bedrock-server.nix @@ -0,0 +1,35 @@ +{ stdenv, fetchurl, patchelf, autoPatchelfHook, curl, gcc-unwrapped, openssl, unzip }: + +stdenv.mkDerivation rec { + pname = "minecraft-bedrock-server"; + version = "1.21.1.03"; + src = fetchurl { + url = "https://minecraft.azureedge.net/bin-linux/bedrock-server-${version}.zip"; + sha256 = "sha256-96re6vDreW+hQsozi4xwjS+5EsAaKju5fZAQpRK7bqs="; + }; + sourceRoot = "."; + nativeBuildInputs = [ + (patchelf.overrideDerivation(old: { + postPatch = '' + substituteInPlace src/patchelf.cc \ + --replace "32 * 1024 * 1024" "512 * 1024 * 1024" + ''; + })) + autoPatchelfHook + curl + gcc-unwrapped + openssl + unzip + ]; + installPhase = '' + install -m755 -D bedrock_server $out/bin/bedrock_server + rm bedrock_server + rm server.properties + rm permissions.json + mkdir -p $out/var + cp -a . $out/var/lib + ''; + fixupPhase = '' + autoPatchelf $out/bin/bedrock_server + ''; +}
diff --git a/pkgs/overlay.nix b/pkgs/overlay.nix @@ -2,23 +2,24 @@ final: prev: { - writePythonScriptBin = (final.callPackage ./writePythonScriptBin.nix {}).writePythonScriptBin; + writePythonScriptBin = (final.callPackage ./writePythonScriptBin.nix {}).writePythonScriptBin; - pleroma = prev.pleroma.overrideAttrs (old: { + pleroma = prev.pleroma.overrideAttrs (old: { patches = [ ./0001-PATCH-Separate-webfinger-domain-from-host-domain.patch ]; }); - phockup = final.callPackage ./phockup.nix {}; - gotosocial = final.callPackage ./gotosocial {}; - AirSane = final.callPackage ./AirSane {}; - cinny = final.callPackage ./cinny.nix {}; - mbusd = final.callPackage ./mbusd.nix {}; - homebridge = final.callPackage ./homebridge {}; - agenix = final.callPackage ./agenix {}; - mastoFE-standalone = final.callPackage ./masto-fe-standalone {}; + phockup = final.callPackage ./phockup.nix {}; + gotosocial = final.callPackage ./gotosocial {}; + AirSane = final.callPackage ./AirSane {}; + cinny = final.callPackage ./cinny.nix {}; + mbusd = final.callPackage ./mbusd.nix {}; + homebridge = final.callPackage ./homebridge {}; + agenix = final.callPackage ./agenix {}; + mastoFE-standalone = final.callPackage ./masto-fe-standalone {}; - usbtan-cli = final.callPackage ./usbtan-cli {}; - rofi-iwd-wifi-menu = final.callPackage ./rofi-iwd-wifi-menu.nix {}; + usbtan-cli = final.callPackage ./usbtan-cli {}; + rofi-iwd-wifi-menu = final.callPackage ./rofi-iwd-wifi-menu.nix {}; + minecraft-bedrock-server = final.callPackage ./minecraft-bedrock-server.nix {}; }