Minecraft Server: Difference between revisions
Cleaned up some of the grammar surrounding the newly added Server.jar segment, also realised that the last edit I did might not count as a minor edit... oops (sorry). Therefore I'll leave this as a non-minor edit (if you want to revert the addition of the "server.jar" remove the last change by me too), so that people have time to review this change (I think that's how it works) |
Added a segment for downloading modded server versions (that are not paper or purpur. Either with nix-minecraft or with the provided server.jar (moved that segment up abit and reworded it to fit in better) |
||
| Line 8: | Line 8: | ||
The minimum example to have a Minecraft server running on localhost at the default port of <code>25565</code>. By setting the <code>eula</code> option to <code>true</code>, you are agreeing to the [https://www.minecraft.net/en-us/eula Minecraft EULA]. | The minimum example to have a Minecraft server running on localhost at the default port of <code>25565</code>. By setting the <code>eula</code> option to <code>true</code>, you are agreeing to the [https://www.minecraft.net/en-us/eula Minecraft EULA]. | ||
{{file| | {{file|||<nowiki> | ||
services.minecraft-server.enable = true; | services.minecraft-server.enable = true; | ||
services.minecraft-server.eula = true; | services.minecraft-server.eula = true; | ||
</nowiki>}} | </nowiki>|name=/etc/nixos/configuration.nix|lang=nix}} | ||
== Configuration == | == Configuration == | ||
| Line 17: | Line 17: | ||
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 <code>43000</code>. | 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 <code>43000</code>. | ||
{{file| | {{file|||<nowiki> | ||
services.minecraft-server = { | services.minecraft-server = { | ||
enable = true; | enable = true; | ||
| Line 39: | Line 39: | ||
jvmOpts = "-Xms2048M -Xmx2048M"; | jvmOpts = "-Xms2048M -Xmx2048M"; | ||
}; | }; | ||
</nowiki>}} | </nowiki>|name=/etc/nixos/configuration.nix|lang=nix}} | ||
You might want to view the [https://minecraft.wiki/w/Server.properties#Keys list of all available server properties for the vanilla server]. | You might want to view the [https://minecraft.wiki/w/Server.properties#Keys list of all available server properties for the vanilla server]. | ||
See [[#See also]] for recommended JVM flags for the <code>jvmOpts</code> option. These primarily depend on your [[Java]] version. | See [[#See also]] for recommended JVM flags for the <code>jvmOpts</code> option. These primarily depend on your [[Java]] version. | ||
== Modded servers == | |||
Minecraft-server provides both support for vanilla and Papermc servers. If you would like to install other mod-loaders such as [https://fabricmc.net/use/server/ Fabric] and [https://quiltmc.org/en/install/server/ Quilt], you would have to take a slightly different approach; | |||
{| class="wikitable" | |||
|+Mod-loaders available on nixpkgs | |||
!Loader | |||
!Available on nixpkgs? | |||
|- | |||
|Vanilla | |||
|Yes | |||
|- | |||
|Fabric | |||
|No | |||
|- | |||
|Quilt | |||
|No | |||
|- | |||
|Paper | |||
|Yes | |||
|- | |||
|Purpur | |||
|Yes | |||
|- | |||
|NeoForge | |||
|No | |||
|- | |||
|Velocity | |||
|No | |||
|} | |||
=== Using flakes === | |||
[https://github.com/Infinidoge/nix-minecraft Nix-minecraft] is a [[Flakes|Nix flakes]] based attempt at better supporting modded servers and has support for managing multiple servers on one system. | |||
Check out the install guide for [https://github.com/Infinidoge/nix-minecraft#installation installing Nix-minecraft]. | |||
Here is the above example configuration.nix but with <code>fabric 26.2</code>, and the server called <code>example</code>{{file|||<nowiki> | |||
services.minecraft-servers = { | |||
enable = true; | |||
eula = true; | |||
servers.example = { | |||
openFirewall = true; # Opens the port the server is running on (by default 25565 but in this case 43000) | |||
# Specifies what package the server should run on | |||
# This example uses the current latest version of Fabric | |||
# The override is here due to a little quirk with nix-minecraft (more detail below this code block) | |||
package = pkgs.fabricServers.fabric-26_2.override { jre_headless = pkgs.openjdk25_headless; }; | |||
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"; | |||
}; | |||
}; | |||
</nowiki>|name=configuration.nix|lang=nix}} | |||
==== Package syntax ==== | |||
<syntaxhighlight lang="nix"> | |||
pkgs.<loader>Servers.<loader>-<version> # for a specific release. | |||
pkgs.<loader>-server # for the latest release | |||
pkgs.<loader>Servers.<loader> # equivalent to above | |||
</syntaxhighlight><sup>''<code><loader></code> refers to the mod loader, such as <code>vanilla</code> , <code>fabric</code>, <code>quilt</code>, <code>paper</code>, <code>purpur</code>, <code>neoforge</code>, and <code>velocity</code>. <code><version></code> refers to the version of minecraft, formatted as <code>26_1_2</code>, <code>1_18_2</code>, or <code>25w10a</code>.''</sup> | |||
==== Why the override? ==== | |||
Due to mojang changing the version formatting in versions <code>≥26.1</code>. The packages (not in [[nixpkgs]]) use ''[https://minecraft.wiki/w/Tutorial:Setting_up_a_Java_Edition_server#Version_requirements the wrong version of Java]''<syntaxhighlight lang="nix"> | |||
# fabric 26.1 with the correct java version | |||
pkgs.fabricServers.fabric-26_1.override { jre_headless = pkgs.openjdk25_headless } | |||
</syntaxhighlight> | |||
=== Imperatively (server.jar) === | |||
Some mods like [https://www.betterthanadventure.net/installation-guide/ BTA!], are not supported by [https://github.com/Infinidoge/nix-minecraft Nix-minecraft] nor [[nixpkgs]]. If so then using the <code>server.jar</code> file might be a simpler approach. | |||
''<sup>Make sure to move the <code>server.jar</code> file inside a separate directory, or else it might spawn server files where you don't want them.</sup>'' | |||
==== Installation ==== | |||
Step 1. Install ''[https://minecraft.wiki/w/Tutorial:Setting_up_a_Java_Edition_server#Version_requirements the appropriate version of Java] .''<syntaxhighlight lang="nixos">pkgs.jdkX # replace the 'X' with the correct java version number here</syntaxhighlight>Step 2. Run the provided <code>server.jar</code> with java (add any extra JVM args as you see fit)<syntaxhighlight lang="nixos"> | |||
java -Xmx4G -jar /path/to/server.jar -nogui | |||
</syntaxhighlight>''The <code>-Xmx</code> flag sets the max memory allocation (here 4GB). The <code>-nogui</code> flag disables the minecraft server gui'' | |||
== Tips and tricks == | == Tips and tricks == | ||
| Line 68: | Line 157: | ||
Example minimal configuration: | Example minimal configuration: | ||
{{file| | {{file|||<nowiki> | ||
services.minecraft-server.serverProperties = { | services.minecraft-server.serverProperties = { | ||
enable-rcon = true; | enable-rcon = true; | ||
"rcon.password" = "your password"; | "rcon.password" = "your password"; | ||
}; | }; | ||
</nowiki>}} | </nowiki>|name=/etc/nixos/configuration.nix|lang=nix}} | ||
=== Use a different server === | === Use a different server === | ||
| Line 94: | Line 183: | ||
To use IPv4 by default, add <code>-Djava.net.preferIPv4Stack=true</code> to <code>jvmOpts</code>. | To use IPv4 by default, add <code>-Djava.net.preferIPv4Stack=true</code> to <code>jvmOpts</code>. | ||
== See also == | == See also == | ||
Revision as of 16:26, 6 September 2026
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.
Modded servers
Minecraft-server provides both support for vanilla and Papermc servers. If you would like to install other mod-loaders such as Fabric and Quilt, you would have to take a slightly different approach;
| Loader | Available on nixpkgs? |
|---|---|
| Vanilla | Yes |
| Fabric | No |
| Quilt | No |
| Paper | Yes |
| Purpur | Yes |
| NeoForge | No |
| Velocity | No |
Using flakes
Nix-minecraft is a Nix flakes based attempt at better supporting modded servers and has support for managing multiple servers on one system.
Check out the install guide for installing Nix-minecraft.
Here is the above example configuration.nix but with fabric 26.2, and the server called example
services.minecraft-servers = {
enable = true;
eula = true;
servers.example = {
openFirewall = true; # Opens the port the server is running on (by default 25565 but in this case 43000)
# Specifies what package the server should run on
# This example uses the current latest version of Fabric
# The override is here due to a little quirk with nix-minecraft (more detail below this code block)
package = pkgs.fabricServers.fabric-26_2.override { jre_headless = pkgs.openjdk25_headless; };
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";
};
};
Package syntax
pkgs.<loader>Servers.<loader>-<version> # for a specific release.
pkgs.<loader>-server # for the latest release
pkgs.<loader>Servers.<loader> # equivalent to above
<loader> refers to the mod loader, such as vanilla , fabric, quilt, paper, purpur, neoforge, and velocity. <version> refers to the version of minecraft, formatted as 26_1_2, 1_18_2, or 25w10a.
Why the override?
Due to mojang changing the version formatting in versions ≥26.1. The packages (not in nixpkgs) use the wrong version of Java
# fabric 26.1 with the correct java version
pkgs.fabricServers.fabric-26_1.override { jre_headless = pkgs.openjdk25_headless }
Imperatively (server.jar)
Some mods like BTA!, are not supported by Nix-minecraft nor nixpkgs. If so then using the server.jar file might be a simpler approach.
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.
Installation
Step 1. Install the appropriate version of Java .
pkgs.jdkX # replace the 'X' with the correct java version number here
Step 2. Run the provided server.jar with java (add any extra JVM args as you see fit)
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
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.
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.