From c203aa37742042c7c183a9123866ff37e8eec606 Mon Sep 17 00:00:00 2001 From: Omar Brikaa Date: Wed, 23 Feb 2022 15:18:40 +0200 Subject: [PATCH] Added dotnet fsharp --- runtimes/default.nix | 1 + runtimes/dotnet-sdk-fsharp.nix | 80 ++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 runtimes/dotnet-sdk-fsharp.nix diff --git a/runtimes/default.nix b/runtimes/default.nix index 3d9f65c..9dab5f6 100644 --- a/runtimes/default.nix +++ b/runtimes/default.nix @@ -54,4 +54,5 @@ args: { "gnat-ada" = import ./gnat-ada.nix args; "rust" = import ./rust.nix args; "dotnet-sdk-csharp" = import ./dotnet-sdk-csharp.nix args; + "dotnet-sdk-fsharp" = import ./dotnet-sdk-fsharp.nix args; } diff --git a/runtimes/dotnet-sdk-fsharp.nix b/runtimes/dotnet-sdk-fsharp.nix new file mode 100644 index 0000000..be0ca26 --- /dev/null +++ b/runtimes/dotnet-sdk-fsharp.nix @@ -0,0 +1,80 @@ +{pkgs, piston, ...}: +let + nugetPkg = pkgs.stdenv.mkDerivation { + pname = "fsharp-nuget-packages"; + version = pkgs.dotnet-sdk.version; + + dontUnpack = true; + dontBuild = true; + dontConfigure = true; + dontFixup = true; + dontPatch = true; + + buildInputs = [ + pkgs.dotnet-sdk + ]; + installPhase = '' + mkdir $out + cd $out + export HOME=$PWD + dotnet new console -lang F# -o fs_cache_application + rm -rf fs_cache_application + ''; + }; + pkg = pkgs.dotnet-sdk; +in piston.mkRuntime { + language = "fsharp"; + version = pkg.version; + runtime = "dotnet-sdk"; + + aliases = [ + "fsharp.net" + "fs" + "f#" + "fs.net" + "f#.net" + "fsharp-dotnet" + "fs-dotnet" + "f#-dotnet" + "dotnet-fsharp" + "dotnet-fs" + "dotnet-fs" + ]; + + compile = '' + export HOME=${nugetPkg} + ${pkg}/dotnet build --help > /dev/null # Supress welcome message + first_file=$1 + shift + rename 's/$/\.fs/' "$@" # Add .fs extension + ${pkg}/dotnet new console -lang F# -o . --no-restore + mv $first_file Program.fs + ${pkg}/dotnet restore --source ${nugetPkg}/.nuget/packages + ${pkg}/dotnet build --no-restore + ''; + + run = '' + export HOME=${nugetPkg} + shift + ${pkg}/dotnet bin/Debug/net6.0/$(basename $(realpath .)).dll "$@" + ''; + + tests = [ + (piston.mkTest { + files = { + "test.fs" = '' + open System + + [] + let main argv = + Console.WriteLine argv[0] + 0 + ''; + }; + args = ["OK"]; + stdin = ""; + packages = []; + main = "test.fs"; + }) + ]; +}