@@ -0,0 +1,142 @@
1+{ stdenv, lib, fetchurl, makeWrapper, fakeroot, file, getopt
2+, gtk2, gdk_pixbuf, glib, mesa_glu, postgresql, nss, nspr
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
7+, mono, libgnomeui, gnome_vfs, gnome-sharp, gtk-sharp
8+}:
9+
10+let
11+ libPath64 = lib.makeLibraryPath [
12+ gcc.cc gtk2 gdk_pixbuf glib mesa_glu postgresql nss nspr
13+ alsaLib GConf cups libcap fontconfig freetype pango
14+ cairo dbus expat zlib libpng12
15+ libX11 libXcursor libXdamage libXfixes libXrender libXi
16+ libXcomposite libXext libXrandr libXtst libSM libICE libxcb
17+ ];
18+ libPath32 = lib.makeLibraryPath [ gcc_32bit.cc ];
19+ binPath = lib.makeBinPath [ nodejs gnutar ];
20+ developBinPath = lib.makeBinPath [ mono ];
21+ developLibPath = lib.makeLibraryPath [
22+ glib libgnomeui gnome_vfs gnome-sharp gtk-sharp gtk-sharp.gtk
23+ ];
24+ developDotnetPath = lib.concatStringsSep ":" [
25+ gnome-sharp gtk-sharp
26+ ];
27+
28+ ver = "5.3.5";
29+ build = "f1";
30+ date = "20160525";
31+ pkgVer = "${ver}${build}";
32+ fullVer = "${pkgVer}+${date}";
33+
34+in stdenv.mkDerivation rec {
35+ name = "unity-editor-${version}";
36+ version = pkgVer;
37+
38+ src = fetchurl {
39+ url = "http://download.unity3d.com/download_unity/linux/unity-editor-installer-${fullVer}.sh";
40+ sha256 = "0lmc65175fdvbyn3565pjlg6cc4l5i58fj7bxzi5cqykkbzv5wdm";
41+ };
42+
43+ nosuidLib = ./unity-nosuid.c;
44+
45+ nativeBuildInputs = [ makeWrapper fakeroot file getopt ];
46+
47+ outputs = [ "out" "monodevelop" "sandbox" ];
48+
49+ unpackPhase = ''
50+ echo -e 'q\ny' | fakeroot sh $src
51+ sourceRoot="unity-editor-${pkgVer}"
52+ '';
53+
54+ buildPhase = ''
55+ patchFile() {
56+ ftype="$(file -b "$1")"
57+ if [[ "$ftype" =~ LSB\ .*dynamically\ linked ]]; then
58+ if [[ "$ftype" =~ 32-bit ]]; then
59+ rpath="${libPath32}"
60+ intp="$(cat $NIX_CC/nix-support/dynamic-linker-m32)"
61+ else
62+ rpath="${libPath64}"
63+ intp="$(cat $NIX_CC/nix-support/dynamic-linker)"
64+ fi
65+
66+ rpath="$(patchelf --print-rpath "$1"):$rpath"
67+ if [[ "$ftype" =~ LSB\ shared ]]; then
68+ patchelf \
69+ --set-rpath "$rpath" \
70+ "$1"
71+ elif [[ "$ftype" =~ LSB\ executable ]]; then
72+ patchelf \
73+ --set-rpath "$rpath" \
74+ --interpreter "$intp" \
75+ "$1"
76+ fi
77+ fi
78+ }
79+
80+ cd Editor
81+
82+ $CC -fPIC -shared -o libunity-nosuid.so $nosuidLib -ldl
83+ strip libunity-nosuid.so
84+
85+ # Exclude PlaybackEngines to build something that can be run on FHS-compliant Linuxes
86+ find . -name PlaybackEngines -prune -o -executable -type f -print | while read path; do
87+ patchFile "$path"
88+ done
89+
90+ cd ..
91+ '';
92+
93+ installPhase = ''
94+ install -Dm755 Editor/chrome-sandbox $sandbox/bin/unity-chrome-sandbox
95+
96+ unitydir="$out/opt/Unity/Editor"
97+ mkdir -p $unitydir
98+ mv Editor/* $unitydir
99+ ln -sf /var/setuid-wrappers/unity-chrome-sandbox $unitydir/chrome-sandbox
100+
101+ mkdir -p $out/share/applications
102+ sed "/^Exec=/c\Exec=$out/bin/unity-editor" \
103+ < unity-editor.desktop \
104+ > $out/share/applications/unity-editor.desktop
105+
106+ install -D unity-editor-icon.png $out/share/icons/hicolor/256x256/apps/unity-editor-icon.png
107+
108+ mkdir -p $out/bin
109+ makeWrapper $unitydir/Unity $out/bin/unity-editor \
110+ --prefix LD_PRELOAD : "$unitydir/libunity-nosuid.so" \
111+ --prefix PATH : "${binPath}"
112+
113+ developdir="$monodevelop/opt/Unity/MonoDevelop"
114+ mkdir -p $developdir
115+ mv MonoDevelop/* $developdir
116+
117+ mkdir -p $monodevelop/share/applications
118+ sed "/^Exec=/c\Exec=$monodevelop/bin/unity-monodevelop" \
119+ < unity-monodevelop.desktop \
120+ > $monodevelop/share/applications/unity-monodevelop.desktop
121+
122+ mkdir -p $monodevelop/bin
123+ makeWrapper $developdir/bin/monodevelop $monodevelop/bin/unity-monodevelop \
124+ --prefix PATH : "${developBinPath}" \
125+ --prefix LD_LIBRARY_PATH : "${developLibPath}" \
126+ --prefix MONO_GAC_PREFIX : "${developDotnetPath}"
127+ '';
128+
129+ dontStrip = true;
130+
131+ meta = with stdenv.lib; {
132+ homepage = https://unity3d.com/;
133+ description = "Game development tool";
134+ longDescription = ''
135+ Popular development platform for creating 2D and 3D multiplatform games
136+ and interactive experiences.
137+ '';
138+ license = licenses.unfree;
139+ platforms = [ "x86_64-linux" ];
140+ maintainers = with maintainers; [ jb55 ];
141+ };
142+}