HOWTO: Setting up a NixOS Minecraft server using the newest version of Minecraft

After setting up a Minecraft server I noticed that my game refused to connect to the server, because the server version was already too old (1.14 at the time), despite being the newest one available on Nixpkgs. I figured out a way to override the version to the newest one (1.14.3 at the time of writing).

First, you need to find out the download url to the newest version of Minecraft, see here: https://www.minecraft.net/download/server/

You also need the SHA-256 checksum of the file.

You can either use nix-prefetch-url command

nix-prefetch-url https://launcher.mojang.com/v1/objects/d0d0fe2b1dc6ab4c65554cb734270872b72dadd6/server.jar
[34.3 MiB DL]
path is '/nix/store/4fi6dfqf4i74zbinnbwsmnbcmqv0gqbi-server.jar'
0f0v0kqz2v5758551yji1vj6xf43lvbma30v3crz4h7cpzq5c8ll

or download the file and run

sha256sum server.jar 
942256f0bfec40f2331b1b0c55d7a683b86ee40e51fa500a2aa76cf1f1041b38  server.jar

Then create a Minecraft server configuration where you override the package with the desired version. Here’s an example:

  services.minecraft-server = {
    enable = true;
    eula = true; #required

    # other options go here. see https://github.com/NixOS/nixpkgs/blob/ef89b398b865290bb9efbae4874a772e5dc5ed9f/nixos/modules/services/games/minecraft-server.nix

    package = let 
      version = "1.14.3";
      url = "https://launcher.mojang.com/v1/objects/d0d0fe2b1dc6ab4c65554cb734270872b72dadd6/server.jar";
      sha256 = "942256f0bfec40f2331b1b0c55d7a683b86ee40e51fa500a2aa76cf1f1041b38";
    in (pkgs.minecraft-server_1_14.overrideAttrs (old: rec {
      name = "minecraft-server-${version}";
      inherit version;

      src = pkgs.fetchurl {
        inherit url sha256;
      };      
    }));
  };

Happy mining and crafting!

4 Likes

FWIW you can use nix-prefetch-url to fetch the file and calculate its hash, so you don’t need to download it separately.

2 Likes

I’ve updated minecraft-server to the latest version in nixpkgs, so your extra config shouldn’t be necessary for much longer if you’re on nixos-unstable. You’re also welcome to make PRs updating it yourself — see Nixpkgs 23.11 manual | Nix & NixOS for an explanation of how, and feel free to ask here or on IRC if you need any help with it!

4 Likes

Thanks for the quick update!

Because Minecraft is a game that gets constantly updated (and newer versions of the game don’t work with older versions of the server), I figured that my solution will also be useful in the future.

Imagine this: New version of the game comes out on a Friday, the kids are going to spend a good portion of the weekend playing the game, the server admin needs to quickly bump up the version number of the server to match the clients, effective immediately. This is where I hope my solution will be helpful.

1 Like

You can have a local clone of nixpkgs and build from there — if you edit pkgs/games/minecraft-server/default.nix to reflect the new version, you can then run nixos-rebuild switch -I nixpkgs=path/to/your/nixpkgs, the kids will be happy and you can make a PR from there :wink:

1 Like

Or if you don’t want to maintain a local nixpkgs clone, create an overlay.

https://nixos.wiki/wiki/Overlays#On_the_system_level

Of course, a PR benefits everyone :wink: .

1 Like

You can also use a matching version on the client. Don’t Minecraft support this in the official Launcher?

You can also use MultiMC.