summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinnnus <[email protected]>2025-01-29 08:16:17 +0100
committerLinnnus <[email protected]>2025-01-29 09:42:39 +0100
commit835a904ac68a9003af02f7c0dfd817a42ecd1a35 (patch)
tree77369275036b86c648fa1ce7e67fbd3d39e62b48
parent8ad025f59c6360c0fdcc5670e40c2855cb836c51 (diff)
on-demand-minecraft: Add data-dir option
-rw-r--r--hosts/ahmed/configuration.nix3
-rw-r--r--modules/nixos/on-demand-minecraft/default.nix26
2 files changed, 20 insertions, 9 deletions
diff --git a/hosts/ahmed/configuration.nix b/hosts/ahmed/configuration.nix
index 222b77c..25be8d0 100644
--- a/hosts/ahmed/configuration.nix
+++ b/hosts/ahmed/configuration.nix
@@ -67,6 +67,9 @@
# Seed requested by Tobias.
server-properties."level-seed" = "1727502807";
+
+ # I changed the default location after creating the world.
+ data-dir = "/srv/minecrafter/papermc-1.21.4-15";
};
services.cloudflare-dyndns.domains = ["minecraft.linus.onl"];
diff --git a/modules/nixos/on-demand-minecraft/default.nix b/modules/nixos/on-demand-minecraft/default.nix
index 999f67b..c5552fe 100644
--- a/modules/nixos/on-demand-minecraft/default.nix
+++ b/modules/nixos/on-demand-minecraft/default.nix
@@ -133,16 +133,28 @@ in {
jvm-options = mkOption {
description = "JVM options for the Minecraft server. List of command line arguments.";
- type = types.listOf lib.types.str;
+ type = with types; listOf str;
default = ["-Xmx2048M" "-Xms2048M"];
};
+
+ data-dir = mkOption {
+ description = ''
+ Where to store game files.
+
+ Note that you may have to clear this directory when changing
+ `services.on-demand-minecraft.package`, as the servers may be confused
+ about files they don't understand.
+ '';
+ type = types.path;
+ default = "/var/lib/minecraft";
+ };
};
config = mkIf cfg.enable {
# Create a user to run the server under.
users.users.minecrafter = {
description = "On-demand minecraft server service user";
- home = "/srv/minecrafter";
+ home = cfg.data-dir;
createHome = true;
group = "minecrafter";
isSystemUser = true;
@@ -203,15 +215,11 @@ in {
})
cfg.whitelist));
- # HACK: Each server is given its own subdirectory so
- # incompatibilities between servers don't cause complaints.
- # FIXME: This hack will break everything when trying to upgrade servers.
start-server = pkgs.writeShellScript "minecraft-server-start" ''
# Switch to runtime directory.
- export RUNTIME_DIR="${config.users.users.minecrafter.home}/${cfg.package.name}/"
- ${pkgs.busybox}/bin/mkdir -p "$RUNTIME_DIR"
- ${pkgs.busybox}/bin/chown minecrafter:minecrafter "$RUNTIME_DIR"
- cd "$RUNTIME_DIR"
+ ${pkgs.busybox}/bin/mkdir -p "${cfg.data-dir}"
+ ${pkgs.busybox}/bin/chown minecrafter:minecrafter "${cfg.data-dir}"
+ cd "${cfg.data-dir}"
# Set up/update environment for server
ln -sf ${eula-file} eula.txt