summaryrefslogtreecommitdiff
path: root/minecraft.nix
diff options
context:
space:
mode:
Diffstat (limited to 'minecraft.nix')
-rw-r--r--minecraft.nix40
1 files changed, 40 insertions, 0 deletions
diff --git a/minecraft.nix b/minecraft.nix
new file mode 100644
index 0000000..d40d80a
--- /dev/null
+++ b/minecraft.nix
@@ -0,0 +1,40 @@
+{lib, ...}:{
+ # The Mojang server jar is unfreeRedistributable, so it has to be allowed by name.
+ nixpkgs.config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [
+ "minecraft-server"
+ ];
+
+ services.minecraft-server = {
+ enable = true;
+ eula = true;
+ openFirewall = true; # Opens the port the server is running on (25565)
+ declarative = true;
+ whitelist = {
+ # This is a mapping of Minecraft usernames to to the players' UUIDs
+ mr_5aturn = "2b811fad-e419-401e-9185-70ab279219b5";
+ };
+ serverProperties = {
+ server-port = 25565;
+ difficulty = "normal";
+ gamemode = "survival";
+ max-players = 5;
+ motd = "NixOS Minecraft server!";
+ white-list = true;
+ };
+ jvmOpts = "-Xms4096M -Xmx4096M";
+ };
+
+ systemd.services.minecraft-server = {
+ startLimitBurst = 5;
+ startLimitIntervalSec = 300;
+ serviceConfig = {
+ NoNewPrivileges = true;
+
+ ProtectSystem = "full";
+
+ MemoryMax = "6G";
+ TasksMax = 512;
+ RestartSec = "10s";
+ };
+ };
+}