Jump to content

Minecraft Server: Difference between revisions

From NixOS Wiki
DoggoBit (talk | contribs)
No edit summary
 
(9 intermediate revisions by 2 users not shown)
Line 6: Line 6:
== Setup ==
== Setup ==


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].


{{unfree}}
{{file|/etc/nixos/configuration.nix|nix|<nowiki>
{{file|/etc/nixos/configuration.nix|nix|<nowiki>
services.minecraft-server.enable = true;
services.minecraft-server.enable = true;
Line 16: Line 15:
== Configuration ==
== 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 <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|/etc/nixos/configuration.nix|nix|<nowiki>
{{file|/etc/nixos/configuration.nix|nix|<nowiki>
Line 38: Line 37:
     allow-cheats = true;
     allow-cheats = true;
   };
   };
   jvmOpts = "-Xms4092M -Xmx4092M -XX:+UseG1GC -XX:+CMSIncrementalPacing -XX:+CMSClassUnloadingEnabled -XX:ParallelGCThreads=2 -XX:MinHeapFreeRatio=5 -XX:MaxHeapFreeRatio=10";
   jvmOpts = "-Xms2048M -Xmx4096M";
};
};
</nowiki>}}
</nowiki>}}
You might want to view the [https://minecraft.wiki/w/Server.properties#Keys list of all available server properties for the vanilla server].


== Tips and tricks ==
== Tips and tricks ==
=== Use a different server version/package ===
To use a specific server version, or another Minecraft server—such as [https://papermc.io/ PaperMC]—change <code>services.minecraft-server.package</code> to a nix package that represents your desired server.
For example:
<code>services.minecraft-server.package = pkgs.minecraftServers.vanilla-1-12;</code>
or
<code>services.minecraft-server.package = pkgs.papermc;</code>
=== Accessing the Minecraft server console ===
The Minecraft server console allows you to view server logs and issue [https://minecraft.wiki/w/Commands commands] to the server interactively. The Minecraft server console is <strong>not</strong> directly accessible on NixOS—unlike on imperative systems, where running the server through a shell command provides the interactive console to the current terminal session.
==== Accessing logs ====
Since the Minecraft server runs as a systemd service, you can access its stdout through the systemd journal:
<code>journalctl -eu minecraft-server.service</code>
The logs are also available in the <code>logs</code> subdirectory of the server's data directory, which is configured via <code>services.minecraft-server.dataDir</code>. The default value for this option is <code>/var/lib/minecraft</code>.
==== 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 <code>/run/minecraft-server.stdin</code>:
<code>echo "say Removed Herobrine" > /run/minecraft-server.stdin</code>
2. Using the [https://minecraft.wiki/w/RCON server's provided RCON feature].
Example minimal configuration:
{{file|/etc/nixos/configuration.nix|nix|<nowiki>
services.minecraft-server.serverProperties = {
    enable-rcon = true;
    "rcon.password" = "your password";
};
</nowiki>}}


=== Prefer IPv4 ===
=== Prefer IPv4 ===


To use IPv4 by default, add <code>-Djava.net.preferIPv4Stack=true</code> to <code>jvmOpts</code> (the first two options are just the defaults)
To use IPv4 by default, add <code>-Djava.net.preferIPv4Stack=true</code> to <code>jvmOpts</code>.
 
== See also ==


<syntaxhighlight lang="nix">
* [https://github.com/Infinidoge/nix-minecraft 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.
jvmOpts = "-Xmx2048M -Xms2048M -Djava.net.preferIPv4Stack=true";
* [https://docs.papermc.io/paper/aikars-flags/ Aikar's flags] or the [https://github.com/Mukul1127/Minecraft-Java-Flags Minecraft performance flags benchmark] for setting additional JVM options in the <code>jvmOpts</code> option.
</syntaxhighlight>


[[Category: Applications]]
[[Category: Applications]]
[[Category: Gaming]]
[[Category: Gaming]]

Latest revision as of 15:53, 29 August 2025

⤧︎
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 blocky sandbox game Minecraft. Currently only servers for the Java Edition of the game 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 from Minecraft usernames to UUIDs. You can use https://mcuuid.net/ to get a Minecraft UUID for a username
    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 -Xmx4096M";
};

You might want to view the list of all available server properties for the vanilla server.

Tips and tricks

Use a different server version/package

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;

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 imperative systems, where running the server through a shell command provides the interactive console to the current terminal session.

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";
 };

Prefer IPv4

To use IPv4 by default, add -Djava.net.preferIPv4Stack=true to jvmOpts.

See also