Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1{ lib, stdenv, fetchurl, bison, pkg-config, glib, gettext, perl, libgdiplus, libX11, callPackage, ncurses, zlib
2, withLLVM ? false, cacert, Foundation, libobjc, python3, version, sha256, autoconf, libtool, automake, cmake, which
3, gnumake42
4, enableParallelBuilding ? true
5, srcArchiveSuffix ? "tar.bz2"
6, extraPatches ? []
7}:
8
9let
10 llvm = callPackage ./llvm.nix { };
11in
12stdenv.mkDerivation rec {
13 pname = "mono";
14 inherit version;
15
16 src = fetchurl {
17 inherit sha256;
18 url = "https://download.mono-project.com/sources/mono/${pname}-${version}.${srcArchiveSuffix}";
19 };
20
21 nativeBuildInputs = [ automake bison cmake pkg-config which gnumake42 ];
22 buildInputs = [
23 glib gettext perl libgdiplus libX11 ncurses zlib python3 autoconf libtool
24 ] ++ lib.optionals stdenv.isDarwin [ Foundation libobjc ];
25
26 configureFlags = [
27 "--x-includes=${libX11.dev}/include"
28 "--x-libraries=${libX11.out}/lib"
29 "--with-libgdiplus=${libgdiplus}/lib/libgdiplus.so"
30 ] ++ lib.optionals withLLVM [
31 "--enable-llvm"
32 "--with-llvm=${llvm}"
33 ];
34
35 configurePhase = ''
36 patchShebangs autogen.sh mcs/build/start-compiler-server.sh
37 ./autogen.sh --prefix $out $configureFlags
38 '';
39
40 # We want pkg-config to take priority over the dlls in the Mono framework and the GAC
41 # because we control pkg-config
42 patches = [ ./pkgconfig-before-gac.patch ] ++ extraPatches;
43
44 # Patch all the necessary scripts. Also, if we're using LLVM, we fix the default
45 # LLVM path to point into the Mono LLVM build, since it's private anyway.
46 preBuild = ''
47 makeFlagsArray=(INSTALL=`type -tp install`)
48 substituteInPlace mcs/class/corlib/System/Environment.cs --replace /usr/share "$out/share"
49 '' + lib.optionalString withLLVM ''
50 substituteInPlace mono/mini/aot-compiler.c --replace "llvm_path = g_strdup (\"\")" "llvm_path = g_strdup (\"${llvm}/bin/\")"
51 '';
52
53 # Fix mono DLLMap so it can find libX11 to run winforms apps
54 # libgdiplus is correctly handled by the --with-libgdiplus configure flag
55 # Other items in the DLLMap may need to be pointed to their store locations, I don't think this is exhaustive
56 # https://www.mono-project.com/Config_DllMap
57 postBuild = ''
58 find . -name 'config' -type f | xargs \
59 sed -i -e "s@libX11.so.6@${libX11.out}/lib/libX11.so.6@g"
60 '';
61
62 # Without this, any Mono application attempting to open an SSL connection will throw with
63 # The authentication or decryption has failed.
64 # ---> Mono.Security.Protocol.Tls.TlsException: Invalid certificate received from server.
65 postInstall = ''
66 echo "Updating Mono key store"
67 $out/bin/cert-sync ${cacert}/etc/ssl/certs/ca-bundle.crt
68 ''
69 # According to [1], gmcs is just mcs
70 # [1] https://github.com/mono/mono/blob/master/scripts/gmcs.in
71 + ''
72 ln -s $out/bin/mcs $out/bin/gmcs
73 '';
74
75 inherit enableParallelBuilding;
76
77 meta = with lib; {
78 # Per nixpkgs#151720 the build failures for aarch64-darwin are fixed since 6.12.0.129
79 broken = stdenv.isDarwin && stdenv.isAarch64 && lib.versionOlder version "6.12.0.129";
80 homepage = "https://mono-project.com/";
81 description = "Cross platform, open source .NET development framework";
82 platforms = with platforms; darwin ++ linux;
83 maintainers = with maintainers; [ thoughtpolice obadz vrthra ];
84 license = licenses.free; # Combination of LGPL/X11/GPL ?
85 };
86}