1# Temporaririly avoid dependency on dotnetbuildhelpers to avoid rebuilding many times while working on it
2
3{ lib, stdenv, fetchurl, pkg-config, autoconf, automake, which, mono, msbuild, dotnetbuildhelpers, dotnetPackages }:
4
5stdenv.mkDerivation rec {
6 pname = "fsharp";
7 version = "4.1.34";
8
9 src = fetchurl {
10 url = "https://github.com/fsharp/fsharp/archive/${version}.tar.gz";
11 sha256 = "0cv6p5pin962vhbpsji40nkckkag5c96kq5qihvg60pc1z821p0i";
12 };
13
14 nativeBuildInputs = [ pkg-config ];
15 buildInputs = [
16 autoconf
17 automake
18 which
19 mono
20 msbuild
21 dotnetbuildhelpers
22 dotnetPackages.FsCheck262
23 dotnetPackages.FSharpCompilerTools
24 dotnetPackages.FSharpCore302
25 dotnetPackages.FSharpCore3125
26 dotnetPackages.FSharpCore4001
27 dotnetPackages.FSharpCore4117
28 dotnetPackages.FSharpData225
29 dotnetPackages.FsLexYacc706
30 dotnetPackages.MicrosoftDiaSymReader
31 dotnetPackages.MicrosoftDiaSymReaderPortablePdb
32 dotnetPackages.NUnit350
33 dotnetPackages.SystemCollectionsImmutable131
34 dotnetPackages.SystemReflectionMetadata
35 dotnetPackages.SystemValueTuple
36 ];
37
38 # https://github.com/mono/mono/tree/fe0f311a848068ab2d17a9b9dd15326e5712d520/packaging/MacSDK/patches
39 # https://github.com/mono/mono/issues/7805
40 patches = [
41 ./fsharp-IsPathRooted-type-inference.patch
42 ./fsharp-string-switchName.patch
43 ./fsharp-path-overloads.patch
44 ./fsharp-GetFileNameWithoutExtension-type-inference.patch
45 ];
46
47 configurePhase = ''
48 substituteInPlace ./autogen.sh --replace "/usr/bin/env sh" "${stdenv.shell}"
49 ./autogen.sh --prefix $out
50 '';
51
52 preBuild = ''
53 substituteInPlace Makefile --replace "MONO_ENV_OPTIONS=\$(monoopts) mono .nuget/NuGet.exe restore packages.config -PackagesDirectory packages -ConfigFile .nuget/NuGet.Config" "true"
54 substituteInPlace src/fsharp/Fsc-proto/Fsc-proto.fsproj --replace "<FSharpCoreOptSigFiles Include=\"\$(FSharpCoreLkgPath)\\FSharp.Core.dll\" />" ""
55 substituteInPlace src/fsharp/Fsc-proto/Fsc-proto.fsproj --replace "<FSharpCoreOptSigFiles Include=\"\$(FSharpCoreLkgPath)\\FSharp.Core.optdata\" />" ""
56 substituteInPlace src/fsharp/Fsc-proto/Fsc-proto.fsproj --replace "<FSharpCoreOptSigFiles Include=\"\$(FSharpCoreLkgPath)\\FSharp.Core.sigdata\" />" ""
57 substituteInPlace src/fsharp/Fsc-proto/Fsc-proto.fsproj --replace "<FSharpCoreOptSigFiles Include=\"\$(FSharpCoreLkgPath)\\FSharp.Core.xml\" />" ""
58
59 rm -rf packages
60 mkdir packages
61
62 ln -s ${dotnetPackages.FsCheck262}/lib/dotnet/FsCheck packages/FsCheck.2.6.2
63 ln -s ${dotnetPackages.FSharpCompilerTools}/lib/dotnet/FSharp.Compiler.Tools packages/FSharp.Compiler.Tools.4.1.27
64 ln -s ${dotnetPackages.FSharpCore302}/lib/dotnet/FSharp.Core/ packages/FSharp.Core.3.0.2
65 ln -s ${dotnetPackages.FSharpCore3125}/lib/dotnet/FSharp.Core/ packages/FSharp.Core.3.1.2.5
66 ln -s ${dotnetPackages.FSharpCore4001}/lib/dotnet/FSharp.Core/ packages/FSharp.Core.4.0.0.1
67 ln -s ${dotnetPackages.FSharpCore4117}/lib/dotnet/FSharp.Core/ packages/FSharp.Core.4.1.17
68 ln -s ${dotnetPackages.FSharpData225}/lib/dotnet/FSharp.Data/ packages/FSharp.Data.2.2.5
69 ln -s ${dotnetPackages.FsLexYacc706}/lib/dotnet/FsLexYacc/ packages/FsLexYacc.7.0.6
70 ln -s ${dotnetPackages.MicrosoftDiaSymReader}/lib/dotnet/Microsoft.DiaSymReader/ packages/Microsoft.DiaSymReader.1.1.0
71 ln -s ${dotnetPackages.MicrosoftDiaSymReaderPortablePdb}/lib/dotnet/Microsoft.DiaSymReader.PortablePdb/ packages/Microsoft.DiaSymReader.PortablePdb.1.2.0
72 ln -s ${dotnetPackages.NUnit350}/lib/dotnet/NUnit/ packages/NUnit.3.5.0
73 ln -s ${dotnetPackages.SystemCollectionsImmutable131}/lib/dotnet/System.Collections.Immutable/ packages/System.Collections.Immutable.1.3.1
74 ln -s ${dotnetPackages.SystemReflectionMetadata}/lib/dotnet/System.Reflection.Metadata/ packages/System.Reflection.Metadata.1.4.2
75 ln -s ${dotnetPackages.SystemValueTuple}/lib/dotnet/System.ValueTuple/ packages/System.ValueTuple.4.3.1
76 '';
77
78 # Signing /home/jdanek/nix/nixpkgs/build/fss/fsharp-4.1.34/again/fsharp-4.1.34/Release/fsharp30/net40/bin/FSharp.Core.dll with Mono key
79 # ERROR: Unknown error during processing: System.UnauthorizedAccessException: Access to the path
80 # "Release/fsharp30/net40/bin/FSharp.Core.dll" is denied.
81 preInstall = ''
82 find Release/ -name FSharp.Core.dll -exec chmod u+w {} \;
83 '';
84
85 # Set up some symlinks for backwards compatibility.
86 postInstall = ''
87 ln -s $out/bin/fsharpc $out/bin/fsc
88 ln -s $out/bin/fsharpi $out/bin/fsi
89 for dll in "$out/lib/mono/fsharp"/FSharp*.dll
90 do
91 create-pkg-config-for-dll.sh "$out/lib/pkgconfig" "$dll"
92 done
93 '';
94
95 doInstallCheck = true;
96 installCheckPhase = ''
97 echo 'printf "int = %i" (6 * 7);;' > script.fsx
98 $out/bin/fsi --exec script.fsx | grep "int = 42"
99 $out/bin/fsharpi --exec script.fsx | grep "int = 42"
100 $out/bin/fsharpiAnyCpu --exec script.fsx | grep "int = 42"
101
102 cat > answer.fs <<EOF
103open System
104
105[<EntryPoint>]
106let main argv =
107 printfn "int = %i" (6 * 7)
108 0
109EOF
110
111 $out/bin/fsc answer.fs
112 ${mono}/bin/mono answer.exe | grep "int = 42"
113 '';
114
115 # To fix this error when running:
116 # The file "/nix/store/path/whatever.exe" is an not a valid CIL image
117 dontStrip = true;
118
119 meta = {
120 description = "A functional CLI language";
121 homepage = "https://fsharp.org/";
122 license = lib.licenses.asl20;
123 maintainers = with lib.maintainers; [ thoughtpolice raskin ];
124 platforms = with lib.platforms; unix;
125 };
126}