Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)

shattered-pixel-dungeon: split generic builder

In preparation for the next commits, which will add some forks/mods that
are built the same way.

+143 -106
+6 -99
pkgs/games/shattered-pixel-dungeon/default.nix
··· 1 - { lib, stdenv 2 - , makeWrapper 1 + { callPackage 3 2 , fetchFromGitHub 4 3 , nixosTests 5 - , gradle 6 - , perl 7 - , jre 8 - , libpulseaudio 9 - , makeDesktopItem 10 - , copyDesktopItems 11 4 }: 12 5 13 - let 6 + callPackage ./generic.nix rec { 14 7 pname = "shattered-pixel-dungeon"; 15 8 version = "2.1.4"; 16 9 ··· 21 14 hash = "sha256-WbRvsHxTYYlhJavYVGMGK25fXEfSfnIztJ6KuCgBjF8="; 22 15 }; 23 16 24 - patches = [ 25 - ./disable-beryx.patch 26 - ]; 27 - 28 - postPatch = '' 29 - # disable gradle plugins with native code and their targets 30 - perl -i.bak1 -pe "s#(^\s*id '.+' version '.+'$)#// \1#" build.gradle 31 - perl -i.bak2 -pe "s#(.*)#// \1# if /^(buildscript|task portable|task nsis|task proguard|task tgz|task\(afterEclipseImport\)|launch4j|macAppBundle|buildRpm|buildDeb|shadowJar|robovm)/ ... /^}/" build.gradle 32 - # Remove unbuildable Android/iOS stuff 33 - rm android/build.gradle ios/build.gradle 34 - ''; 35 - 36 - # fake build to pre-download deps into fixed-output derivation 37 - deps = stdenv.mkDerivation { 38 - pname = "${pname}-deps"; 39 - inherit version src patches postPatch; 40 - nativeBuildInputs = [ gradle perl ]; 41 - buildPhase = '' 42 - export GRADLE_USER_HOME=$(mktemp -d) 43 - # https://github.com/gradle/gradle/issues/4426 44 - ${lib.optionalString stdenv.isDarwin "export TERM=dumb"} 45 - gradle --no-daemon desktop:release 46 - ''; 47 - # perl code mavenizes pathes (com.squareup.okio/okio/1.13.0/a9283170b7305c8d92d25aff02a6ab7e45d06cbe/okio-1.13.0.jar -> com/squareup/okio/okio/1.13.0/okio-1.13.0.jar) 48 - installPhase = '' 49 - find $GRADLE_USER_HOME/caches/modules-2 -type f -regex '.*\.\(jar\|pom\)' \ 50 - | perl -pe 's#(.*/([^/]+)/([^/]+)/([^/]+)/[0-9a-f]{30,40}/([^/\s]+))$# ($x = $2) =~ tr|\.|/|; "install -Dm444 $1 \$out/$x/$3/$4/$5" #e' \ 51 - | sh 52 - ''; 53 - outputHashMode = "recursive"; 54 - outputHash = "sha256-i4k5tdo07E1NJwywroaGvRjZ+/xrDp6ra+GTYwTB7uk="; 55 - }; 56 - 57 - desktopItem = makeDesktopItem { 58 - name = "shattered-pixel-dungeon"; 59 - desktopName = "Shattered Pixel Dungeon"; 60 - comment = "An open-source traditional roguelike dungeon crawler"; 61 - icon = "shattered-pixel-dungeon"; 62 - exec = "shattered-pixel-dungeon"; 63 - terminal = false; 64 - categories = [ "Game" "AdventureGame" ]; 65 - keywords = [ "roguelike" "dungeon" "crawler" ]; 66 - }; 67 - 68 - in stdenv.mkDerivation rec { 69 - inherit pname version src patches postPatch; 70 - 71 - nativeBuildInputs = [ gradle perl makeWrapper copyDesktopItems ]; 72 - 73 - desktopItems = [ desktopItem ]; 74 - 75 - buildPhase = '' 76 - runHook preBuild 77 - 78 - export GRADLE_USER_HOME=$(mktemp -d) 79 - # https://github.com/gradle/gradle/issues/4426 80 - ${lib.optionalString stdenv.isDarwin "export TERM=dumb"} 81 - # point to offline repo 82 - sed -ie "s#repositories {#repositories { maven { url '${deps}' };#g" build.gradle 83 - gradle --offline --no-daemon desktop:release 84 - 85 - runHook postBuild 86 - ''; 87 - 88 - installPhase = '' 89 - runHook preInstall 90 - 91 - install -Dm644 desktop/build/libs/desktop-${version}.jar $out/share/shattered-pixel-dungeon.jar 92 - mkdir $out/bin 93 - makeWrapper ${jre}/bin/java $out/bin/shattered-pixel-dungeon \ 94 - --prefix LD_LIBRARY_PATH : ${libpulseaudio}/lib \ 95 - --add-flags "-jar $out/share/shattered-pixel-dungeon.jar" 96 - 97 - for s in 16 32 48 64 128 256; do 98 - install -Dm644 desktop/src/main/assets/icons/icon_$s.png \ 99 - $out/share/icons/hicolor/''${s}x$s/apps/shattered-pixel-dungeon.png 100 - done 101 - 102 - runHook postInstall 103 - ''; 17 + depsHash = "sha256-i4k5tdo07E1NJwywroaGvRjZ+/xrDp6ra+GTYwTB7uk="; 104 18 105 19 passthru.tests = { 106 20 shattered-pixel-dungeon-starts = nixosTests.shattered-pixel-dungeon; 107 21 }; 108 22 109 - meta = with lib; { 23 + desktopName = "Shattered Pixel Dungeon"; 24 + 25 + meta = { 110 26 homepage = "https://shatteredpixel.com/"; 111 27 downloadPage = "https://github.com/00-Evan/shattered-pixel-dungeon/releases"; 112 28 description = "Traditional roguelike game with pixel-art graphics and simple interface"; 113 - sourceProvenance = with sourceTypes; [ 114 - fromSource 115 - binaryBytecode # deps 116 - ]; 117 - license = licenses.gpl3Plus; 118 - maintainers = with maintainers; [ fgaz ]; 119 - platforms = platforms.all; 120 - # https://github.com/NixOS/nixpkgs/pull/99885#issuecomment-740065005 121 - broken = stdenv.isDarwin; 122 29 }; 123 30 }
-7
pkgs/games/shattered-pixel-dungeon/disable-beryx.patch
··· 38 38 39 39 dependencies { 40 40 implementation project(':core') 41 - @@ -123,4 +124,4 @@ dependencies { 42 - 43 - implementation project(':services:updates:githubUpdates') 44 - implementation project(':services:news:shatteredNews') 45 - -} 46 - \ No newline at end of file 47 - +}
+137
pkgs/games/shattered-pixel-dungeon/generic.nix
··· 1 + # Generic builder for shattered pixel forks/mods 2 + { pname 3 + , version 4 + , src 5 + , depsHash 6 + , meta 7 + , desktopName 8 + , patches ? [ ./disable-beryx.patch ] 9 + 10 + , lib 11 + , stdenv 12 + , makeWrapper 13 + , gradle 14 + , perl 15 + , jre 16 + , libpulseaudio 17 + , makeDesktopItem 18 + , copyDesktopItems 19 + , ... 20 + }@attrs: 21 + 22 + let 23 + cleanAttrs = builtins.removeAttrs attrs [ 24 + "lib" 25 + "stdenv" 26 + "makeWrapper" 27 + "gradle" 28 + "perl" 29 + "jre" 30 + "libpulseaudio" 31 + "makeDesktopItem" 32 + "copyDesktopItems" 33 + ]; 34 + 35 + postPatch = '' 36 + # disable gradle plugins with native code and their targets 37 + perl -i.bak1 -pe "s#(^\s*id '.+' version '.+'$)#// \1#" build.gradle 38 + perl -i.bak2 -pe "s#(.*)#// \1# if /^(buildscript|task portable|task nsis|task proguard|task tgz|task\(afterEclipseImport\)|launch4j|macAppBundle|buildRpm|buildDeb|shadowJar|robovm|git-version)/ ... /^}/" build.gradle 39 + # Remove unbuildable Android/iOS stuff 40 + rm -f android/build.gradle ios/build.gradle 41 + ${attrs.postPatch or ""} 42 + ''; 43 + 44 + desktopItem = makeDesktopItem { 45 + name = pname; 46 + inherit desktopName; 47 + comment = meta.description; 48 + icon = pname; 49 + exec = pname; 50 + terminal = false; 51 + categories = [ "Game" "AdventureGame" ]; 52 + keywords = [ "roguelike" "dungeon" "crawler" ]; 53 + }; 54 + 55 + # fake build to pre-download deps into fixed-output derivation 56 + deps = stdenv.mkDerivation { 57 + pname = "${pname}-deps"; 58 + inherit version src patches postPatch; 59 + nativeBuildInputs = [ gradle perl ] ++ attrs.nativeBuildInputs or []; 60 + buildPhase = '' 61 + export GRADLE_USER_HOME=$(mktemp -d) 62 + # https://github.com/gradle/gradle/issues/4426 63 + ${lib.optionalString stdenv.isDarwin "export TERM=dumb"} 64 + gradle --no-daemon desktop:release 65 + ''; 66 + # perl code mavenizes pathes (com.squareup.okio/okio/1.13.0/a9283170b7305c8d92d25aff02a6ab7e45d06cbe/okio-1.13.0.jar -> com/squareup/okio/okio/1.13.0/okio-1.13.0.jar) 67 + installPhase = '' 68 + find $GRADLE_USER_HOME/caches/modules-2 -type f -regex '.*\.\(jar\|pom\)' \ 69 + | perl -pe 's#(.*/([^/]+)/([^/]+)/([^/]+)/[0-9a-f]{30,40}/([^/\s]+))$# ($x = $2) =~ tr|\.|/|; "install -Dm444 $1 \$out/$x/$3/$4/$5" #e' \ 70 + | sh 71 + ''; 72 + outputHashMode = "recursive"; 73 + outputHash = depsHash; 74 + }; 75 + 76 + in stdenv.mkDerivation (cleanAttrs // { 77 + inherit pname version src patches postPatch; 78 + 79 + nativeBuildInputs = [ 80 + gradle 81 + perl 82 + makeWrapper 83 + copyDesktopItems 84 + ] ++ attrs.nativeBuildInputs or []; 85 + 86 + desktopItems = [ desktopItem ]; 87 + 88 + buildPhase = '' 89 + runHook preBuild 90 + 91 + export GRADLE_USER_HOME=$(mktemp -d) 92 + # https://github.com/gradle/gradle/issues/4426 93 + ${lib.optionalString stdenv.isDarwin "export TERM=dumb"} 94 + # point to offline repo 95 + sed -ie "s#repositories {#repositories { maven { url '${deps}' };#g" build.gradle 96 + gradle --offline --no-daemon desktop:release 97 + 98 + runHook postBuild 99 + ''; 100 + 101 + installPhase = '' 102 + runHook preInstall 103 + 104 + install -Dm644 desktop/build/libs/desktop-*.jar $out/share/${pname}.jar 105 + mkdir $out/bin 106 + makeWrapper ${jre}/bin/java $out/bin/${pname} \ 107 + --prefix LD_LIBRARY_PATH : ${libpulseaudio}/lib \ 108 + --add-flags "-jar $out/share/${pname}.jar" 109 + 110 + for s in 16 32 48 64 128 256; do 111 + # Some forks only have some icons and/or name them slightly differently 112 + if [ -f desktop/src/main/assets/icons/icon_$s.png ]; then 113 + install -Dm644 desktop/src/main/assets/icons/icon_$s.png \ 114 + $out/share/icons/hicolor/''${s}x$s/apps/${pname}.png 115 + fi 116 + if [ -f desktop/src/main/assets/icons/icon_''${s}x$s.png ]; then 117 + install -Dm644 desktop/src/main/assets/icons/icon_''${s}x$s.png \ 118 + $out/share/icons/hicolor/''${s}x$s/apps/${pname}.png 119 + fi 120 + done 121 + 122 + runHook postInstall 123 + ''; 124 + 125 + meta = with lib; { 126 + sourceProvenance = with sourceTypes; [ 127 + fromSource 128 + binaryBytecode # deps 129 + ]; 130 + license = licenses.gpl3Plus; 131 + maintainers = with maintainers; [ fgaz ]; 132 + platforms = platforms.all; 133 + # https://github.com/NixOS/nixpkgs/pull/99885#issuecomment-740065005 134 + broken = stdenv.isDarwin; 135 + mainProgram = pname; 136 + } // meta; 137 + })