@@ -0,0 +1,90 @@
1+{ stdenv, fetchurl, bison, pkgconfig, glib, gettext, perl, libgdiplus, libX11, callPackage, ncurses, zlib, withLLVM ? false, cacert, Foundation, libobjc, python, version, sha256, cmake, autoconf, libtool, automake, gcc }:
2+
3+let
4+ llvm = callPackage ./llvm.nix { };
5+in
6+stdenv.mkDerivation rec {
7+ name = "mono-${version}";
8+
9+ src = fetchurl {
10+ inherit sha256;
11+ url = "https://download.mono-project.com/sources/mono/${name}.tar.bz2";
12+ };
13+
14+ buildInputs =
15+ [ bison pkgconfig glib gettext perl libgdiplus libX11 ncurses zlib python cmake autoconf libtool automake gcc
16+ ]
17+ ++ (stdenv.lib.optionals stdenv.isDarwin [ Foundation libobjc ]);
18+
19+ propagatedBuildInputs = [glib];
20+
21+ NIX_LDFLAGS = if stdenv.isDarwin then "" else "-lgcc_s" ;
22+
23+ # To overcome the bug https://bugzilla.novell.com/show_bug.cgi?id=644723
24+ dontDisableStatic = true;
25+
26+ # In fact I think this line does not help at all to what I
27+ # wanted to achieve: have mono to find libgdiplus automatically
28+ configureFlags = [
29+ "--x-includes=${libX11.dev}/include"
30+ "--x-libraries=${libX11.out}/lib"
31+ "--with-libgdiplus=${libgdiplus}/lib/libgdiplus.so"
32+ ]
33+ ++ stdenv.lib.optionals withLLVM [
34+ "--enable-llvm"
35+ "--enable-llvmloaded"
36+ "--with-llvm=${llvm}"
37+ ];
38+
39+ # Attempt to fix this error when running "mcs --version":
40+ # The file /nix/store/xxx-mono-2.4.2.1/lib/mscorlib.dll is an invalid CIL image
41+ dontStrip = true;
42+
43+ # Parallel building doesn't work, as shows http://hydra.nixos.org/build/2983601
44+ enableParallelBuilding = false;
45+
46+ # We want pkg-config to take priority over the dlls in the Mono framework and the GAC
47+ # because we control pkg-config
48+ patches = [ ./pkgconfig-before-gac-5x.patch ];
49+
50+ # Patch all the necessary scripts. Also, if we're using LLVM, we fix the default
51+ # LLVM path to point into the Mono LLVM build, since it's private anyway.
52+ preBuild = ''
53+ makeFlagsArray=(INSTALL=`type -tp install`)
54+ patchShebangs ./
55+ substituteInPlace mcs/class/corlib/System/Environment.cs --replace /usr/share "$out/share"
56+ '' + stdenv.lib.optionalString withLLVM ''
57+ substituteInPlace mono/mini/aot-compiler.c --replace "llvm_path = g_strdup (\"\")" "llvm_path = g_strdup (\"${llvm}/bin/\")"
58+ echo 11111
59+ '';
60+
61+ # Fix mono DLLMap so it can find libX11 and gdiplus to run winforms apps
62+ # Other items in the DLLMap may need to be pointed to their store locations, I don't think this is exhaustive
63+ # http://www.mono-project.com/Config_DllMap
64+ postBuild = ''
65+ find . -name 'config' -type f | xargs \
66+ sed -i -e "s@libX11.so.6@${libX11.out}/lib/libX11.so.6@g" \
67+ -e "s@/.*libgdiplus.so@${libgdiplus}/lib/libgdiplus.so@g" \
68+ '';
69+
70+ # Without this, any Mono application attempting to open an SSL connection will throw with
71+ # The authentication or decryption has failed.
72+ # ---> Mono.Security.Protocol.Tls.TlsException: Invalid certificate received from server.
73+ postInstall = ''
74+ echo "Updating Mono key store"
75+ $out/bin/cert-sync ${cacert}/etc/ssl/certs/ca-bundle.crt
76+ ''
77+ # According to [1], gmcs is just mcs
78+ # [1] https://github.com/mono/mono/blob/master/scripts/gmcs.in
79+ + ''
80+ ln -s $out/bin/mcs $out/bin/gmcs
81+ '';
82+
83+ meta = {
84+ homepage = http://mono-project.com/;
85+ description = "Cross platform, open source .NET development framework";
86+ platforms = with stdenv.lib.platforms; darwin ++ linux;
87+ maintainers = with stdenv.lib.maintainers; [ viric thoughtpolice obadz vrthra ];
88+ license = stdenv.lib.licenses.free; # Combination of LGPL/X11/GPL ?
89+ };
90+}