mirror of
https://git.sr.ht/~magic_rb/dotfiles
synced 2024-12-11 09:22:02 +01:00
5d516e080b
Signed-off-by: Magic_RB <magic_rb@redalder.org>
78 lines
2.1 KiB
Nix
78 lines
2.1 KiB
Nix
{ pkgs, config, lib, ... }:
|
|
with lib;
|
|
let
|
|
cfg = config.services.minecraft.vanilla;
|
|
in
|
|
{
|
|
options.services.minecraft.vanilla = {
|
|
enable = mkEnableOption "Enable Minecraft server service.";
|
|
|
|
serverPackage = mkOption {
|
|
type = types.package;
|
|
readOnly = true;
|
|
};
|
|
|
|
eulaAccept = mkOption {
|
|
type = with types; bool;
|
|
description = ''
|
|
By changing the setting below to true you are indicating your agreement to Mojang's EULA (https://account.mojang.com/documents/minecraft_eula).
|
|
'';
|
|
default = false;
|
|
};
|
|
|
|
extraJavaArguments = mkOption {
|
|
type = with types; listOf str;
|
|
default = [];
|
|
};
|
|
};
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
services.minecraft.vanilla.serverPackage =
|
|
pkgs.stdenv.mkDerivation {
|
|
pname = "minecraft";
|
|
version = "unknown";
|
|
|
|
src = pkgs.fetchurl {
|
|
url = "https://piston-data.mojang.com/v1/objects/84194a2f286ef7c14ed7ce0090dba59902951553/server.jar";
|
|
hash = "sha256-RIsU/6VxKZ7Sk59dgG4dudHhRLcD+ki32Ab0wv00Tik=";
|
|
executable = true;
|
|
};
|
|
|
|
phases = [ "installPhase" ];
|
|
|
|
installPhase = ''
|
|
mkdir -p $out/bin
|
|
|
|
${lib.getExe pkgs.jdk17} -jar $src --initSettings
|
|
mkdir -p $out/share
|
|
cp server.properties $out/share/
|
|
|
|
cp ${pkgs.writeShellScript "server.sh" ''
|
|
[ -f server.properties ] || cp @out@/share/server.properties .
|
|
${lib.getExe pkgs.jdk17} "$@" -jar @src@
|
|
''} $out/bin/server
|
|
substituteInPlace $out/bin/server --subst-var src --subst-var out
|
|
'';
|
|
};
|
|
|
|
init.services.minecraft-vanilla = {
|
|
script = pkgs.writeShellScript "minecraft-run" ''
|
|
set -xe
|
|
|
|
mkdir -p /var/lib/minecraft/vanilla
|
|
cd /var/lib/minecraft/vanilla
|
|
echo "eula=true" > eula.txt
|
|
${cfg.serverPackage}/bin/server ${concatMapStringsSep " " (x: ''"${x}"'') cfg.extraJavaArguments}
|
|
'';
|
|
enabled = true;
|
|
shutdownOnExit = true;
|
|
};
|
|
|
|
assertions = [
|
|
{ assertion = cfg.eulaAccept;
|
|
message = "You must accept the EULA";
|
|
}
|
|
];
|
|
};
|
|
}
|