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