fork/nix-minecraft
git clone https://git.julia.blue/fork/nix-minecraft
cc15499
lazymc
1{ 2lib , 3fetchurl , 4jre_headless , 5linkFarm , 6makeWrapper , 7minecraft-server , 8runCommand , 9stdenvNoCC , 10udev , 11writeShellApplication , 12zip , 13 14build , 15gameVersion , 16libraryLocks , 17} : 18let 19inherit ( lib ) 20attrValues 21concatLists 22concatStringsSep 23elemAt 24map 25mapAttrs 26splitString 27; 28specifierPath = 29specifier: 30let 31components = builtins . match "^([^:]+):([^:]+):([^@:]+).*" specifier ; 32groupId = elemAt components 0 ; 33artifactId = elemAt components 1 ; 34version = elemAt components 2 ; 35in 36concatStringsSep "/" ( 37( splitString "." groupId ) 38++ [ 39artifactId 40version 41] 42); 43mkLibrary = specifier: rec { 44name = " ${ specifierPath specifier } / ${ path . name } " ; 45path = fetchurl libraryLocks .${ specifier }; 46}; 47repository = linkFarm "neoforge ${ build . version } -libraries" ( 48( map mkLibrary build . libraries ) 49++ [ 50{ 51name = "net/minecraft/server/ ${ minecraft-server . version } /server- ${ minecraft-server . version } .jar" ; 52path = minecraft-server . src ; 53} 54] 55); 56installer-unwrapped = fetchurl build . src ; 57installer = 58let 59name = "neoforge- ${ build . version } -offline-installer" ; 60 61# Add server mappings to the jar so we can perform an offline install. 62# https://github.com/neoforged/LegacyInstaller/blob/e95a1687b24d6c1e4ba87c98ddcd42b83eeba555/src/main/java/net/minecraftforge/installer/actions/FatInstallerAction.java#L79 63# TODO: Can we just add mappings to the classpath rather than directly to the jar? 64fatJar = runCommand " ${ name } " { nativeBuildInputs = [ zip ]; } '' 65install -m 644 -D " ${ installer-unwrapped } " " $ out " 66 67server_mappings=" maven/minecraft/ ${ minecraft-server . version } /server_mappings.txt " 68install -m 644 -D ${ fetchurl gameVersion . mappings } " $ server_mappings " 69 70zip " $ out " " $ server_mappings " 71'' ; 72 73wrapper = writeShellApplication { 74inherit name ; 75runtimeInputs = [ jre_headless ]; 76# Unfortunately, library dependencies cannot just be added to the classpath. The 77# [installer](https://github.com/neoforged/LegacyInstaller/blob/e95a1687b24d6c1e4ba87c98ddcd42b83eeba555/src/main/java/net/minecraftforge/installer/Downloader.java#L114), 78# [and NeoForge itself](https://github.com/neoforged/FancyModLoader/blob/610108bbd862a87c1266076a2592dfbc732e19c4/loader/src/main/java/net/neoforged/fml/loading/LibraryFinder.java#L28) 79# require a `libraries` directory. 80text = '' 81mkdir -p " $ 1 /libraries" 82cp -r --no-preserve=all ${ repository } /* " $ 1 /libraries" 83java -jar ${ fatJar } --offline --installServer " $ 1 " 84'' ; 85}; 86in 87wrapper ; 88in 89stdenvNoCC . mkDerivation rec { 90pname = "neoforge" ; 91version = " ${ gameVersion . version } - ${ build . version } " ; 92dontUnpack = true ; 93 94preferLocalBuild = true ; 95 96buildInputs = [ makeWrapper ]; 97 98buildPhase = '' 99${ lib . getExe installer } $ out 100args =" $ out /libraries/net/neoforged/neoforge/ ${ build . version } /unix_args.txt " 101substituteInPlace " $ args " \ 102--replace-fail " -DlibraryDirectory=libraries " " -DlibraryDirectory= $ out/libraries" \ 103--replace-fail "libraries/" " $ out/libraries/" 104makeWrapper " ${ jre_headless } /bin/java " " $ out/bin/ ${ meta . mainProgram } " \ 105${ lib . optionalString stdenvNoCC . hostPlatform . isLinux "--prefix LD_LIBRARY_PATH : ${ lib . makeLibraryPath [ udev ]} " } \ 106--append-flags "@ $ args " 107'' ; 108 109passthru = { 110inherit repository installer installer-unwrapped ; 111updateScript = ./update.py ; 112gameVersion = gameVersion . version ; 113loaderVersion = build . version ; 114}; 115 116meta = with lib ; { 117description = "Minecraft Server" ; 118homepage = "https://minecraft.net" ; 119license = licenses . unfreeRedistributable ; 120platforms = platforms . unix ; 121maintainers = with maintainers ; [ infinidoge ]; 122mainProgram = "minecraft-server" ; 123}; 124}