Minecraft Server: Difference between revisions
Removed flags from example, they were old and broken (causing minecraft-server to fail upon using them); instead recommended user to find their own flags. Also added a tip on changing server version/package |
No edit summary |
||
Line 15: | 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 59: | Line 59: | ||
<code>services.minecraft-server.package = pkgs.papermc;</code> | <code>services.minecraft-server.package = pkgs.papermc;</code> | ||
== See also == | |||
* [[NixOS modules]], a library for modular [[Overview of the Nix Expression Language#Expressions|Nix expressions]] which powers [[#Declarative Configuration|the declarative configuration of NixOS]]. | |||
[[Category: Applications]] | [[Category: Applications]] | ||
[[Category: Gaming]] | [[Category: Gaming]] |
Revision as of 14:30, 18 August 2025
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.
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 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 look at using using Aikar's flags or the Minecraft performance flags benchmark.
Tips and tricks
Prefer IPv4
To use IPv4 by default, add -Djava.net.preferIPv4Stack=true
to jvmOpts
.
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;
See also
- NixOS modules, a library for modular Nix expressions which powers the declarative configuration of NixOS.