Fsharp does not work on nixos-18.09

I installed fsharp by adding it in configure.nix, after nixos-rebuild switch.

Then I tried to run fsharpc and fsharpi, error message is given as

Unhandled Exception:
System.TypeInitializationException: The type initializer for 'System.Console' threw an exception. ---> System.TypeInitializationException: The type initializer for 'System.ConsoleDriver' threw an exception. ---> System.Exception: Magic number is wrong: 542
  at System.TermInfoReader.ReadHeader (System.Byte[] buffer, System.Int32& position) [0x00028] in <2bf5cbaa96234d758393ee9c32a4b268>:0 
  at System.TermInfoReader..ctor (System.String term, System.String filename) [0x0005f] in <2bf5cbaa96234d758393ee9c32a4b268>:0 
  at System.TermInfoDriver..ctor (System.String term) [0x00055] in <2bf5cbaa96234d758393ee9c32a4b268>:0 
  at System.ConsoleDriver.CreateTermInfoDriver (System.String term) [0x00000] in <2bf5cbaa96234d758393ee9c32a4b268>:0 
  at System.ConsoleDriver..cctor () [0x0004d] in <2bf5cbaa96234d758393ee9c32a4b268>:0 
   --- End of inner exception stack trace ---
  at System.Console.SetupStreams (System.Text.Encoding inputEncoding, System.Text.Encoding outputEncoding) [0x00007] in <2bf5cbaa96234d758393ee9c32a4b268>:0 
  at System.Console..cctor () [0x0008e] in <2bf5cbaa96234d758393ee9c32a4b268>:0 
   --- End of inner exception stack trace ---
  at Microsoft.FSharp.Compiler.Interactive.Shell.evaluateSession@2420 (System.String[] argv, Microsoft.FSharp.Core.Unit unitVar0) [0x00032] in <5b8a550d046a099ca74503830d558a5b>:0 
  at Microsoft.FSharp.Compiler.Interactive.Shell.MainMain (System.String[] argv) [0x00065] in <5b8a550d046a099ca74503830d558a5b>:0 
  at Microsoft.FSharp.Compiler.Interactive.Main.FsiMain (System.String[] argv) [0x00001] in <5b8a550d046a099ca74503830d558a5b>:0 
[ERROR] FATAL UNHANDLED EXCEPTION: System.TypeInitializationException: The type initializer for 'System.Console' threw an exception. ---> System.TypeInitializationException: The type initializer for 'System.ConsoleDriver' threw an exception. ---> System.Exception: Magic number is wrong: 542
  at System.TermInfoReader.ReadHeader (System.Byte[] buffer, System.Int32& position) [0x00028] in <2bf5cbaa96234d758393ee9c32a4b268>:0 
  at System.TermInfoReader..ctor (System.String term, System.String filename) [0x0005f] in <2bf5cbaa96234d758393ee9c32a4b268>:0 
  at System.TermInfoDriver..ctor (System.String term) [0x00055] in <2bf5cbaa96234d758393ee9c32a4b268>:0 
  at System.ConsoleDriver.CreateTermInfoDriver (System.String term) [0x00000] in <2bf5cbaa96234d758393ee9c32a4b268>:0 
  at System.ConsoleDriver..cctor () [0x0004d] in <2bf5cbaa96234d758393ee9c32a4b268>:0 
   --- End of inner exception stack trace ---
  at System.Console.SetupStreams (System.Text.Encoding inputEncoding, System.Text.Encoding outputEncoding) [0x00007] in <2bf5cbaa96234d758393ee9c32a4b268>:0 
  at System.Console..cctor () [0x0008e] in <2bf5cbaa96234d758393ee9c32a4b268>:0 
   --- End of inner exception stack trace ---
  at Microsoft.FSharp.Compiler.Interactive.Shell.evaluateSession@2420 (System.String[] argv, Microsoft.FSharp.Core.Unit unitVar0) [0x00032] in <5b8a550d046a099ca74503830d558a5b>:0 
  at Microsoft.FSharp.Compiler.Interactive.Shell.MainMain (System.String[] argv) [0x00065] in <5b8a550d046a099ca74503830d558a5b>:0 
  at Microsoft.FSharp.Compiler.Interactive.Main.FsiMain (System.String[] argv) [0x00001] in <5b8a550d046a099ca74503830d558a5b>:0 

It’s a known bug/issue in mono, not specific to NixOS:

https://github.com/mono/mono/issues/6752

The work-around is to issue export TERM=xterm.

1 Like