about summary refs log tree commit diff
path: root/modules
diff options
context:
space:
mode:
authorsefidel <contact@sefidel.net>2024-09-09 01:59:29 +0900
committersefidel <contact@sefidel.net>2024-12-22 13:19:18 +0900
commitccb98e61a887938e93b686da949c4e2cff931d6c (patch)
treed3bc41f54c497bd61ca61fdffa2d3f09afa17e3f /modules
parentc1d7272a84cbfab8abbe53cb4934f8cd92342372 (diff)
downloadnixrc-ccb98e61a887938e93b686da949c4e2cff931d6c.tar.gz
nixrc-ccb98e61a887938e93b686da949c4e2cff931d6c.zip
feat(modules): add minecraft-server
Diffstat (limited to 'modules')
-rw-r--r--modules/services/minecraft-server.nix56
1 files changed, 56 insertions, 0 deletions
diff --git a/modules/services/minecraft-server.nix b/modules/services/minecraft-server.nix
new file mode 100644
index 0000000..072c934
--- /dev/null
+++ b/modules/services/minecraft-server.nix
@@ -0,0 +1,56 @@
+{ config, lib, pkgs, ... }:
+
+with lib;
+let
+  cfg = config.modules.services.minecraft-server;
+in
+{
+  options.modules.services.minecraft-server = {
+    enable = mkEnableOption "";
+    package = mkOption { type = types.package; default = pkgs.papermc; };
+    openFirewall = mkOption {
+      type = types.bool;
+      default = false;
+    };
+    bedrockSupport = mkOption {
+      type = types.bool;
+      default = false;
+    };
+    eula = mkOption {
+      type = types.bool;
+      default = false;
+    };
+    dataDir = mkOption {
+      type = types.str;
+      default = "/var/lib/minecraft";
+    };
+  };
+
+  config = mkIf cfg.enable {
+    services.minecraft-server = {
+      enable = true;
+      package = cfg.package;
+      declarative = false;
+      eula = cfg.eula;
+      dataDir = cfg.dataDir;
+      jvmOpts = "-Xms4096M -Xmx4096M"
+        + " -XX:+DisableExplicitGC -XX:+ParallelRefProcEnabled"
+        + " -XX:+UnlockExperimentalVMOptions"
+        + " -XX:+UseG1GC -XX:G1HeapRegionSize=8M -XX:G1HeapWastePercent=5"
+        + " -XX:G1MaxNewSizePercent=40 -XX:G1NewSizePercent=30"
+        + " -XX:G1MixedGCCountTarget=4 -XX:G1MixedGCLiveThresholdPercent=90"
+        + " -XX:G1RSetUpdatingPauseTimePercent=5 -XX:G1ReservePercent=20"
+        + " -XX:InitiatingHeapOccupancyPercent=15 -XX:MaxGCPauseMillis=200"
+        + " -XX:MaxTenuringThreshold=1 -XX:SurvivorRatio=32";
+    };
+
+    modules.persistence.directories = [
+      cfg.dataDir
+    ];
+
+  networking.firewall.allowedTCPPorts = [ 25565 ]
+      ++ optionals (cfg.bedrockSupport) [ 19132 ];
+  networking.firewall.allowedUDPPorts = [ 25565 ]
+      ++ optionals (cfg.bedrockSupport) [ 19132 ];
+  };
+}