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!