Jump to content

Minecraft Server: Difference between revisions

From Official NixOS Wiki
Gobbe (talk | contribs)
m Clearer instructions & reformatting pt.2
Gobbe (talk | contribs)
m tweaks againn :3
 
(6 intermediate revisions by the same user not shown)
Line 92: Line 92:


==== Other versions ====
==== Other versions ====
[https://github.com/Infinidoge/nix-minecraft Nix-minecraft] is based on [[Flakes|Nix flakes]] and supports a couple different modded servers:
<syntaxhighlight lang="nix"># This example uses Nix-minecraft to declare a <version> NeoForge server called <name>
services.minecraft-servers.<name>.package = pkgs.neoforgeServers.neoforge-<version>;
</syntaxhighlight><sup>''Note that the <version> is formatted as <code>26_1_2</code>, <code>1_18_2</code>, or <code>25w10a</code>. Using a specific version could look like this: <code>pkgs.vanillaServer.vanilla-1_8_9</code>''</sup>
 
[https://github.com/Infinidoge/nix-minecraft Nix-minecraft] is a [[Flakes|nix flakes]] based attempt at supporting a few more modded servers:
{| class="wikitable"
{| class="wikitable"
|+
|+
Line 127: Line 131:
|<code>velocityServers.velocity</code>
|<code>velocityServers.velocity</code>
|}
|}
''<small>*Does it use the correct Java for versions <code>≥26.1</code>?</small>''
''<small>*Does it use the correct version of Java for Minecraft <code>≥26.1</code>?</small>''
 
<code>Nix-minecraft</code> supports hosting multiple servers at once, therefore you must name your servers (even if you only have one).
 
Here is an example with a server called <code>example</code> using the latest major fabric version:<syntaxhighlight lang="nix">services.minecraft-servers.example.package = pkgs.fabricServers.fabric;
# ↑ this will not launch ↑
# ↓  this will launch  ↓
services.minecraft-servers.example.package = pkgs.fabricServers.fabric.override
{ jre_headless = pkgs.openjdk25_headless; };
</syntaxhighlight><sup>''Note that the version is formatted as <code>26_1_2</code>, <code>1_18_2</code>, or <code>25w10a</code>. Using a specific version could look like this: <code>pkgs.vanillaServer.vanilla-1_8_9</code>''</sup>


Why doesn't the top example work? For versions <code>≥26.1</code> <code>Nix-minecraft</code> uses ''[https://minecraft.wiki/w/Tutorial:Setting_up_a_Java_Edition_server#Version_requirements the wrong version of Java].''
As stated above, since Minecraft 26.1, some packages ''[https://github.com/Infinidoge/nix-minecraft/issues/211 use the wrong version of Java]'' (presumably due to the [https://www.minecraft.net/en-us/article/minecraft-new-version-numbering-system change in Minecraft version formatting]). To correct this, override with ''[https://minecraft.wiki/w/Tutorial:Setting_up_a_Java_Edition_server#Version_requirements the appropriate version of Java].''<syntaxhighlight lang="nix"># This example declares a 26.1 fabric server called <name>. Needing an override for java 25
{| class="wikitable mw-collapsible mw-collapsed"
services.minecraft-servers.<name>.package = pkgs.fabricServers.fabric-26_1.override
|}
{ jre_headless = pkgs.openjdk25_headless; };</syntaxhighlight>


=== Use an exotic server ===
=== Use a custom server.jar ===
Some mods like [https://www.betterthanadventure.net/installation-guide/ BTA!] are neither supported by <code>Nix-minecraft</code>, nor <code>Nixpkgs</code>. They provide their own <code>server.jar</code> to run with Java, summoning a ''Minecraft server''.  
Some mods like [https://www.betterthanadventure.net/installation-guide/ BTA!] are not supported through previously explored methods. In that case running the server through the provided <code>server.jar</code> is an option ''(if one is provided).''   


''<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>''
''<sup>Do note that doing this is not recommended, and should be seen as a last resort. Also if you really do not want to touch flakes.</sup>''


# Download the <code>server.jar</code>
# Download the <code>server.jar</code>''<small>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.</small>''
# 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>
# 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>
# Run the provided <code>server.jar</code> with java<syntaxhighlight lang="nixos">
# Run the provided <code>server.jar</code> with java<syntaxhighlight lang="nixos">

Latest revision as of 21:17, 7 September 2026

⤧︎
Disambiguation: Not to be confused with the Minecraft client.
🟆︎
Tip: This package is unfree, and will require extra steps to install. You can read more about allowing unfree software in the Nixpkgs Manual.

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.

❄︎ /etc/nixos/configuration.nix
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.

❄︎ /etc/nixos/configuration.nix
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:

❄︎ /etc/nixos/configuration.nix
 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;

Other versions

# This example uses Nix-minecraft to declare a <version> NeoForge server called <name> 
services.minecraft-servers.<name>.package = pkgs.neoforgeServers.neoforge-<version>;

Note that the <version> is formatted as 26_1_2, 1_18_2, or 25w10a. Using a specific version could look like this: pkgs.vanillaServer.vanilla-1_8_9

Nix-minecraft is a nix flakes based attempt at supporting a few more modded servers:

Server * Package name
Vanilla Yes vanillaServers.vanilla
Fabric No fabricServers.fabric
Quilt No quiltServers.quilt
Paper Yes paperServers.paper
Purpur Yes purpurServers.purpur
NeoForge No neoforgeServers.neoforge
Velocity No velocityServers.velocity

*Does it use the correct version of Java for Minecraft ≥26.1?

As stated above, since Minecraft 26.1, some packages use the wrong version of Java (presumably due to the change in Minecraft version formatting). To correct this, override with the appropriate version of Java.

# This example declares a 26.1 fabric server called <name>. Needing an override for java 25
services.minecraft-servers.<name>.package = pkgs.fabricServers.fabric-26_1.override 
{ jre_headless = pkgs.openjdk25_headless; };

Use a custom server.jar

Some mods like BTA! are not supported through previously explored methods. In that case running the server through the provided server.jar is an option (if one is provided).

Do note that doing this is not recommended, and should be seen as a last resort. Also if you really do not want to touch flakes.

  1. Download the server.jarMake sure to move the server.jar file inside a separate directory, or else it might spawn server files where you don't want them.
  2. Install the appropriate version of Java .
    pkgs.jdkX # replace the X with the correct Java version number here
    
  3. Run the provided server.jar with java
    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

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 jvmOpts option. 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.