diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index f6c0c2483928..7544975f04ce 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -209,6 +209,7 @@ in memcached = handleTest ./memcached.nix {}; metabase = handleTest ./metabase.nix {}; minecraft = handleTest ./minecraft.nix {}; + minecraft-server = handleTest ./minecraft-server.nix {}; miniflux = handleTest ./miniflux.nix {}; minio = handleTest ./minio.nix {}; minidlna = handleTest ./minidlna.nix {}; diff --git a/nixos/tests/minecraft-server.nix b/nixos/tests/minecraft-server.nix new file mode 100644 index 000000000000..53780e4636ca --- /dev/null +++ b/nixos/tests/minecraft-server.nix @@ -0,0 +1,37 @@ +let + seed = "2151901553968352745"; + rcon-pass = "foobar"; + rcon-port = 43000; +in import ./make-test-python.nix ({ pkgs, ... }: { + name = "minecraft-server"; + meta = with pkgs.stdenv.lib.maintainers; { maintainers = [ nequissimus ]; }; + + nodes.server = { ... }: { + environment.systemPackages = [ pkgs.mcrcon ]; + + nixpkgs.config.allowUnfree = true; + + services.minecraft-server = { + declarative = true; + enable = true; + eula = true; + serverProperties = { + enable-rcon = true; + level-seed = seed; + online-mode = false; + "rcon.password" = rcon-pass; + "rcon.port" = rcon-port; + }; + }; + + virtualisation.memorySize = 2048; + }; + + testScript = '' + server.wait_for_unit("minecraft-server") + server.wait_for_open_port(${toString rcon-port}) + assert "${seed}" in server.succeed( + "mcrcon -H localhost -P ${toString rcon-port} -p '${rcon-pass}' -c 'seed'" + ) + ''; +}) diff --git a/pkgs/games/minecraft-server/default.nix b/pkgs/games/minecraft-server/default.nix index 5cf39ec35b0e..77181692ec22 100644 --- a/pkgs/games/minecraft-server/default.nix +++ b/pkgs/games/minecraft-server/default.nix @@ -1,4 +1,4 @@ -{ stdenv, fetchurl, jre_headless }: +{ stdenv, fetchurl, nixosTests, jre_headless }: stdenv.mkDerivation { pname = "minecraft-server"; version = "1.16.4"; @@ -25,7 +25,10 @@ stdenv.mkDerivation { phases = "installPhase"; - passthru.updateScript = ./update.sh; + passthru = { + tests = { inherit (nixosTests) minecraft-server; }; + updateScript = ./update.sh; + }; meta = with stdenv.lib; { description = "Minecraft Server";