Jump to content

Minecraft Server: Difference between revisions

From NixOS Wiki
No edit summary
No edit summary
Line 62: Line 62:
== See also ==
== 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]].
* [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.
 


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

Revision as of 14:32, 18 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 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

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