Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at devShellTools-shell 117 lines 3.4 kB view raw
1/* 2 The package definition for an OpenRA out-of-tree mod. 3 It shares code with `engine.nix` by what is defined in `common.nix`. 4 To build an out-of-tree mod it needs the source code of the engine available, 5 and they each need to be build with a specific version or fork of the engine, 6 so the engine needs to be supplied as an argument as well. 7 The engine is relatively small and quick to build, so this is not much of a problem. 8 Building a mod will result in a wrapper script that starts the mod inside the specified engine. 9*/ 10{ 11 lib, 12 stdenv, 13 packageAttrs, 14 patchEngine, 15 wrapLaunchGame, 16 mod, 17 engine, 18}: 19 20let 21 engineSourceName = engine.src.name or "engine"; 22 modSourceName = mod.src.name or "mod"; 23 24in 25# Based on: https://build.opensuse.org/package/show/home:fusion809/openra-ura 26stdenv.mkDerivation ( 27 lib.recursiveUpdate packageAttrs rec { 28 name = "${pname}-${version}"; 29 pname = "openra_2019-${mod.name}"; 30 inherit (mod) version; 31 32 srcs = [ 33 mod.src 34 engine.src 35 ]; 36 37 sourceRoot = "."; 38 39 postUnpack = '' 40 mv ${engineSourceName} ${modSourceName} 41 cd ${modSourceName} 42 ''; 43 44 postPatch = '' 45 cat <<'EOF' > fetch-engine.sh 46 #!/bin/sh 47 exit 0 48 EOF 49 50 sed -i 's/^VERSION.*/VERSION = ${version}/g' Makefile 51 52 dos2unix *.md 53 54 ${patchEngine engineSourceName engine.version} 55 ''; 56 57 configurePhase = '' 58 runHook preConfigure 59 60 make version VERSION=${lib.escapeShellArg version} 61 make -C ${engineSourceName} version VERSION=${lib.escapeShellArg engine.version} 62 63 runHook postConfigure 64 ''; 65 66 checkTarget = "test"; 67 68 installPhase = '' 69 runHook preInstall 70 71 make -C ${engineSourceName} install-engine install-common-mod-files DATA_INSTALL_DIR=$out/lib/${pname} 72 73 cp -r ${engineSourceName}/mods/{${ 74 lib.concatStringsSep "," ( 75 [ 76 "common" 77 "modcontent" 78 ] 79 ++ engine.mods 80 ) 81 }} mods/* \ 82 $out/lib/${pname}/mods/ 83 84 substitute ${./mod-launch-game.sh} $out/lib/openra_2019-${mod.name}/launch-game.sh \ 85 --subst-var out \ 86 --subst-var-by name ${lib.escapeShellArg mod.name} \ 87 --subst-var-by title ${lib.escapeShellArg mod.title} \ 88 --subst-var-by assetsError ${lib.escapeShellArg mod.assetsError} 89 chmod +x $out/lib/openra_2019-${mod.name}/launch-game.sh 90 91 ${wrapLaunchGame "_2019-${mod.name}" "openra-${mod.name}"} 92 93 substitute ${./openra-mod.desktop} $(mkdirp $out/share/applications)/${pname}.desktop \ 94 --subst-var-by name ${lib.escapeShellArg mod.name} \ 95 --subst-var-by title ${lib.escapeShellArg mod.title} \ 96 --subst-var-by description ${lib.escapeShellArg mod.description} 97 98 cp README.md $(mkdirp $out/share/doc/packages/${pname})/README.md 99 100 [[ -e mods/${mod.name}/icon.png ]] && mod_icon=mods/${mod.name}/icon.png || { 101 [[ -e mods/${mod.name}/logo.png ]] && mod_icon=mods/${mod.name}/logo.png || mod_icon=packaging/linux/mod_256x256.png 102 } 103 cp "$mod_icon" $(mkdirp $out/share/pixmaps)/${pname}.png 104 105 for size in 16 32 48 64 128 256; do 106 size=''${size}x''${size} 107 cp packaging/linux/mod_''${size}.png $(mkdirp $out/share/icons/hicolor/''${size}/apps)/${pname}.png 108 done 109 110 runHook postInstall 111 ''; 112 113 meta = { 114 inherit (mod) description homepage; 115 }; 116 } 117)