From 1f0c70f1c259df7a754229b66aa9a51565d864a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tristan=20Dani=C3=ABl=20Maat?= Date: Sun, 19 Jul 2020 21:14:21 +0100 Subject: [PATCH] Add minecraft service This is an initial configuration to restore old services. Obviously, vendoring everything in a tarball is pretty awful, and if I ever wanted to open source this, that would be a problem. I intend to create a proper derivation in time, but including mods is difficult from some initial experimentation. --- .gitattributes | 1 + Makefile | 2 +- etc/nixos/configuration.nix | 2 + etc/nixos/services/configs/minecraft.tar.gz | 3 + etc/nixos/services/minecraft.nix | 126 ++++++++++++++++++++ 5 files changed, 133 insertions(+), 1 deletion(-) create mode 100644 .gitattributes create mode 100644 etc/nixos/services/configs/minecraft.tar.gz create mode 100644 etc/nixos/services/minecraft.nix diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..f087b42 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +*.tar.gz filter=lfs diff=lfs merge=lfs -text diff --git a/Makefile b/Makefile index 0856e62..f76ef73 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ tlaternet.qcow2: nix-shell -p qemu --run 'qemu-img create -f qcow2 $@ 10G' run: result tlaternet.qcow2 - QEMU_OPTS="-m 4096 -nographic" QEMU_NET_OPTS="hostfwd=tcp::2222-:2222,hostfwd=tcp::8000-:80" ./result/bin/run-tlaternet-vm + QEMU_OPTS="-m 4096 -nographic" QEMU_NET_OPTS="hostfwd=tcp::2222-:2222,hostfwd=tcp::8000-:80,hostfwd=tcp::25565-:25565" ./result/bin/run-tlaternet-vm format: $(wildcard etc/nixos/**/*.nix) nix-shell -p nixpkgs-fmt --run 'nixpkgs-fmt $^' diff --git a/etc/nixos/configuration.nix b/etc/nixos/configuration.nix index fcf203d..4d5e5f9 100644 --- a/etc/nixos/configuration.nix +++ b/etc/nixos/configuration.nix @@ -15,6 +15,7 @@ ./services/gitea.nix ./services/nextcloud.nix ./services/tlaternet.nix + ./services/minecraft.nix ]; networking = { @@ -32,6 +33,7 @@ 443 2222 2221 + 25565 ]; }; }; diff --git a/etc/nixos/services/configs/minecraft.tar.gz b/etc/nixos/services/configs/minecraft.tar.gz new file mode 100644 index 0000000..c8de1ed --- /dev/null +++ b/etc/nixos/services/configs/minecraft.tar.gz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c0c4cb989a487da07a1ca469b370e1d7ab17a6a13c087871611b6cc8bf5684f6 +size 147313790 diff --git a/etc/nixos/services/minecraft.nix b/etc/nixos/services/minecraft.nix new file mode 100644 index 0000000..5a1bb10 --- /dev/null +++ b/etc/nixos/services/minecraft.nix @@ -0,0 +1,126 @@ +{ pkgs, ... }: + +let + ops = pkgs.writeText "ops.json" (builtins.toJSON [ + { + uuid = "140d177a-966f-41b8-a4c0-e305babd291b"; + name = "TLATER"; + level = 4; + bypassesPlayerLimit = true; + } + ]); + whitelist = pkgs.writeText "whitelist.json" (builtins.toJSON [ + { + uuid = "59cd1648-14a4-4bcf-8f5a-2e1bde678f2c"; + name = "romino25"; + } + { + uuid = "0ab6e3d1-544a-47e7-8538-2e6c248e49a4"; + name = "lasi25"; + } + { + uuid = "140d177a-966f-41b8-a4c0-e305babd291b"; + name = "TLATER"; + } + ]); + properties = pkgs.writeText "server.properties" '' + #Minecraft server properties + #Sun Jul 19 16:04:54 GMT 2020 + max-tick-time=60000 + generator-settings= + allow-nether=true + force-gamemode=false + gamemode=0 + enable-query=false + player-idle-timeout=0 + difficulty=1 + spawn-monsters=true + op-permission-level=4 + pvp=false + snooper-enabled=true + level-type=DEFAULT + hardcore=false + enable-command-block=false + max-players=4 + network-compression-threshold=256 + resource-pack-sha1= + max-world-size=29999984 + server-port=25565 + server-ip= + spawn-npcs=true + allow-flight=true + level-name=world + view-distance=15 + resource-pack= + spawn-animals=true + white-list=true + generate-structures=true + online-mode=true + max-build-height=256 + level-seed= + prevent-proxy-connections=false + use-native-transport=true + motd=Adventures met die broers + enable-rcon=false + ''; + +in +{ + docker-containers = { + minecraft = { + image = "tlaternet/minecraft"; + imageFile = pkgs.dockerTools.buildImage { + name = "tlaternet/minecraft"; + tag = "latest"; + runAsRoot = '' + mkdir -p /var/lib/ + ${pkgs.gzip}/bin/gzip -dc ${./configs/minecraft.tar.gz} | ${pkgs.gnutar}/bin/tar -xf - -C /var/lib + echo 'eula=true' > /var/lib/minecraft/eula.txt + cp -f ${properties} /var/lib/minecraft + ''; + config = { + Cmd = [ "${pkgs.jre_headless}/bin/java" + "-Xms2G" + "-Xmx2G" + # Using recommended flags from https://mcflags.emc.gs + "-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" + "-jar" + "/var/lib/minecraft/forge-1.12.2-14.23.5.2854.jar" + "nogui" + ]; + Volumes = { + "/var/lib/minecraft/world" = {}; + }; + WorkingDir = "/var/lib/minecraft"; + ExposedPorts = { + "25565" = {}; + }; + }; + }; + ports = [ + "25565:25565" + ]; + volumes = [ + "${ops}:/var/lib/minecraft/ops.json:ro" + "${whitelist}:/var/lib/minecraft/whitelist.json:ro" + ]; + }; + }; +} -- 2.44.1