Minecraft Server
Minecraft Server is a server for the sandbox game Minecraft. Currently, only servers for the Java Edition of Minecraft are supported.
Setup
The minimum example to have a Minecraft server running on localhost at the default port of 25565. By setting the eula option to true, you are agreeing to the Minecraft EULA.
services.minecraft-server.enable = true;
services.minecraft-server.eula = true;
Configuration
This example is a more thorough declarative configuration that sets a few options including opening the firewall, restricting the server to only whitelisted users and setting the port to 43000.
services.minecraft-server = {
enable = true;
eula = true;
openFirewall = true; # Opens the port the server is running on (by default 25565 but in this case 43000)
declarative = true;
whitelist = {
# This is a mapping of Minecraft usernames to to the players' UUIDs
username1 = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
username2 = "yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy";
};
serverProperties = {
server-port = 43000;
difficulty = 3;
gamemode = 1;
max-players = 5;
motd = "NixOS Minecraft server!";
white-list = true;
allow-cheats = true;
};
jvmOpts = "-Xms2048M -Xmx2048M";
};
You might want to view the list of all available server properties for the vanilla server.
See #See also for recommended JVM flags for the jvmOpts option. These primarily depend on your Java version.
Tips and tricks
Accessing the Minecraft server console
The Minecraft server console allows you to view server logs and issue commands to the server interactively. The Minecraft server console is not directly accessible on NixOS—unlike on non-declarative systems, where running the server through a shell command provides the interactive console to the current terminal.
Accessing logs
Since the Minecraft server runs as a systemd service, you can access its stdout through the systemd journal:
journalctl -eu minecraft-server.service
The logs are also available in the logs subdirectory of the server's data directory, which is configured via services.minecraft-server.dataDir. The default value for this option is /var/lib/minecraft.
Issuing commands
There are two ways to issue commands to the Minecraft server:
1. Writing to the server’s stdin via its named pipe at /run/minecraft-server.stdin:
echo "say Removed Herobrine" > /run/minecraft-server.stdin
2. Using the server's provided RCON feature.
Example minimal configuration:
services.minecraft-server.serverProperties = {
enable-rcon = true;
"rcon.password" = "your password";
};
Use a different server
To use a specific server version, or another Minecraft server—such as PaperMC—change services.minecraft-server.package to a nix package that represents your desired server.
For example:
services.minecraft-server.package = pkgs.minecraftServers.vanilla-1-12;
or
services.minecraft-server.package = pkgs.papermc;
Prefer IPv4
To use IPv4 by default, add -Djava.net.preferIPv4Stack=true to jvmOpts.
Server.jar
Some mods like Fabric or BTA!, that might not be available through nixpkgs, provide their own server.jar files.
Make sure to move the server.jar file inside a separate directory, or else it might spawn server files where you don't want them.
Server.jar dependencies
In order to run server.jar (or any jar file in general), you will need to install the appropriate version of Java .
pkgs.jdkX # replace the 'X' with the correct java version number here
Then just run the server.jar file and append optional JVM flags
java -Xmx4G -jar /path/to/server.jar -nogui
The -Xmx flag sets the max memory allocation (here 4GB). The -nogui flag disables the minecraft server gui
See also
- nix-minecraft, a flake based attempt to better support Minecraft related content for the Nix ecosystem. It can be used for more complex server setups, including mods and plugins.
- https://exa.y2k.diy/garden/jvm-args for setting additional JVM flags in the
jvmOptsoption. Some server-related software—like the Velocity proxy—have their own recommended JVM flags list. - https://mcuuid.net to get a player's UUID from their current username or vice versa.