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, chromium
8}:
9
10let
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
34in 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" ];
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 unitydir="$out/opt/Unity/Editor"
95 mkdir -p $unitydir
96 mv Editor/* $unitydir
97 ln -sf /var/setuid-wrappers/${chromium.sandboxExecutableName} $unitydir/chrome-sandbox
98
99 mkdir -p $out/share/applications
100 sed "/^Exec=/c\Exec=$out/bin/unity-editor" \
101 < unity-editor.desktop \
102 > $out/share/applications/unity-editor.desktop
103
104 install -D unity-editor-icon.png $out/share/icons/hicolor/256x256/apps/unity-editor-icon.png
105
106 mkdir -p $out/bin
107 makeWrapper $unitydir/Unity $out/bin/unity-editor \
108 --prefix LD_PRELOAD : "$unitydir/libunity-nosuid.so" \
109 --prefix PATH : "${binPath}"
110
111 developdir="$monodevelop/opt/Unity/MonoDevelop"
112 mkdir -p $developdir
113 mv MonoDevelop/* $developdir
114
115 mkdir -p $monodevelop/share/applications
116 sed "/^Exec=/c\Exec=$monodevelop/bin/unity-monodevelop" \
117 < unity-monodevelop.desktop \
118 > $monodevelop/share/applications/unity-monodevelop.desktop
119
120 mkdir -p $monodevelop/bin
121 makeWrapper $developdir/bin/monodevelop $monodevelop/bin/unity-monodevelop \
122 --prefix PATH : "${developBinPath}" \
123 --prefix LD_LIBRARY_PATH : "${developLibPath}" \
124 --prefix MONO_GAC_PREFIX : "${developDotnetPath}"
125 '';
126
127 dontStrip = 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; [ jb55 ];
139 };
140}