Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at release-19.03 137 lines 4.3 kB view raw
1{ stdenv, lib, fetchurl, makeWrapper, file, getopt 2, gtk2, gdk_pixbuf, glib, libGL, libGLU, nss, nspr, udev, tbb 3, alsaLib, GConf, cups, libcap, fontconfig, freetype, pango 4, cairo, dbus, expat, zlib, libpng12, nodejs, gnutar, gcc, gcc_32bit 5, libX11, libXcursor, libXdamage, libXfixes, libXrender, libXi 6, libXcomposite, libXext, libXrandr, libXtst, libSM, libICE, libxcb, chromium 7}: 8 9let 10 libPath64 = lib.makeLibraryPath [ 11 gcc.cc gtk2 gdk_pixbuf glib libGL libGLU nss nspr 12 alsaLib GConf cups libcap fontconfig freetype pango 13 cairo dbus expat zlib libpng12 udev tbb 14 libX11 libXcursor libXdamage libXfixes libXrender libXi 15 libXcomposite libXext libXrandr libXtst libSM libICE libxcb 16 ]; 17 libPath32 = lib.makeLibraryPath [ gcc_32bit.cc ]; 18 binPath = lib.makeBinPath [ nodejs gnutar ]; 19 20 ver = "2017.4.10"; 21 build = "f1"; 22 23in stdenv.mkDerivation rec { 24 name = "unity-editor-${version}"; 25 version = "${ver}x${build}"; 26 27 src = fetchurl { 28 url = "https://beta.unity3d.com/download/14396d76537e/LinuxEditorInstaller/Unity.tar.xz"; 29 sha256 = "e1b4fe41c0ff793f7a9146c49a8eca8c71d30abdfa3e81922bd69699810b3f67"; 30 }; 31 32 nosuidLib = ./unity-nosuid.c; 33 34 nativeBuildInputs = [ makeWrapper file getopt ]; 35 36 outputs = [ "out" ]; 37 38 sourceRoot = "."; 39 40 buildPhase = '' 41 cd Editor 42 43 $CC -fPIC -shared -o libunity-nosuid.so $nosuidLib -ldl 44 strip libunity-nosuid.so 45 46 cd .. 47 ''; 48 49 installPhase = '' 50 unitydir="$out/opt/Unity/Editor" 51 mkdir -p $unitydir 52 mv Editor/* $unitydir 53 ln -sf /run/wrappers/bin/${chromium.sandboxExecutableName} $unitydir/chrome-sandbox 54 55 mkdir -p $out/bin 56 makeWrapper $unitydir/Unity $out/bin/unity-editor \ 57 --prefix LD_PRELOAD : "$unitydir/libunity-nosuid.so" \ 58 --prefix PATH : "${binPath}" 59 ''; 60 61 preFixup = '' 62 patchFile() { 63 ftype="$(file -b "$1")" 64 if [[ "$ftype" =~ LSB\ .*dynamically\ linked ]]; then 65 if [[ "$ftype" =~ 32-bit ]]; then 66 rpath="${libPath32}" 67 intp="$(cat $NIX_CC/nix-support/dynamic-linker-m32)" 68 else 69 rpath="${libPath64}" 70 intp="$(cat $NIX_CC/nix-support/dynamic-linker)" 71 fi 72 73 # Save origin-relative parts of rpath. 74 originRpath="$(patchelf --print-rpath "$1" | sed "s/:/\n/g" | grep "^\$ORIGIN" | paste -sd ":" - || echo "")" 75 rpath="$originRpath:$rpath" 76 77 patchelf --set-rpath "$rpath" "$1" 78 patchelf --set-interpreter "$intp" "$1" 2> /dev/null || true 79 fi 80 } 81 82 upm_linux=$unitydir/Data/Resources/Upm/upm-linux 83 84 orig_size=$(stat --printf=%s $upm_linux) 85 86 # Exclude PlaybackEngines to build something that can be run on FHS-compliant Linuxes 87 find $unitydir -name PlaybackEngines -prune -o -type f -print | while read path; do 88 patchFile "$path" 89 done 90 91 new_size=$(stat --printf=%s $upm_linux) 92 93 ###### zeit-pkg fixing starts here. 94 # we're replacing plaintext js code that looks like 95 # PAYLOAD_POSITION = '1234 ' | 0 96 # [...] 97 # PRELUDE_POSITION = '1234 ' | 0 98 # ^-----20-chars-----^^------22-chars------^ 99 # ^-- grep points here 100 # 101 # var_* are as described above 102 # shift_by seems to be safe so long as all patchelf adjustments occur 103 # before any locations pointed to by hardcoded offsets 104 105 var_skip=20 106 var_select=22 107 shift_by=$(expr $new_size - $orig_size) 108 109 function fix_offset { 110 # $1 = name of variable to adjust 111 location=$(grep -obUam1 "$1" $upm_linux | cut -d: -f1) 112 location=$(expr $location + $var_skip) 113 value=$(dd if=$upm_linux iflag=count_bytes,skip_bytes skip=$location \ 114 bs=1 count=$var_select status=none) 115 value=$(expr $shift_by + $value) 116 echo -n $value | dd of=$upm_linux bs=1 seek=$location conv=notrunc 117 } 118 119 fix_offset PAYLOAD_POSITION 120 fix_offset PRELUDE_POSITION 121 ''; 122 123 dontStrip = true; 124 dontPatchELF = true; 125 126 meta = with stdenv.lib; { 127 homepage = https://unity3d.com/; 128 description = "Game development tool"; 129 longDescription = '' 130 Popular development platform for creating 2D and 3D multiplatform games 131 and interactive experiences. 132 ''; 133 license = licenses.unfree; 134 platforms = [ "x86_64-linux" ]; 135 maintainers = with maintainers; [ jb55 ]; 136 }; 137}