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