diff --git a/hosts/NixGame/configuration.nix b/hosts/NixGame/configuration.nix index 7c00adf..12d395c 100644 --- a/hosts/NixGame/configuration.nix +++ b/hosts/NixGame/configuration.nix @@ -8,6 +8,7 @@ imports = [ # Include the results of the hardware scan. ./hardware-configuration.nix + ./gameservers.d/minecraft/earth.nix ]; networking.hostName = "NixGame"; diff --git a/hosts/NixGame/gameservers.d/minecraft/earth.nix b/hosts/NixGame/gameservers.d/minecraft/earth.nix new file mode 100644 index 0000000..57b858c --- /dev/null +++ b/hosts/NixGame/gameservers.d/minecraft/earth.nix @@ -0,0 +1,35 @@ +{ config, pkgs, ... }: + +{ + systemd.services.minecraft-container = { + description = "Minecraft Server [earth.nix]"; + after = [ "network-online.target" ]; + wants = [ "network-online.target" ]; + serviceConfig = { + ExecStart = '' + ${pkgs.podman}/bin/podman run \ + --rm \ + --name minecraft-server \ + -v /var/lib/minecraft/earth.nix:/data \ + -p 25565:25565 \ + -p 24454:24454/udp \ + ghcr.io/graalvm/graalvm-community:17 \ + /data/run.sh + ''; + ExecStop = "${pkgs.podman}/bin/podman stop minecraft-server"; + Restart = "always"; + RestartSec = "10s"; + }; + + # Ensure the directory exists + preStart = '' + mkdir -p /var/lib/minecraft/earth.nix/ + ''; + wantedBy = [ "multi-user.target" ]; + }; + + # Give Podman permission to access persistent storage + systemd.tmpfiles.rules = [ + "d /var/lib/minecraft/earth.nix 0755 root root" + ]; +}