Solving libX11 not found on F# .Net Core project

Steps to reproduce:

  • Install the latest .Net sdk on NixOS
  • dotnet new -i JaggerJo.Avalonia.FuncUI.Templates
  • dotnet new avalonia-funcUI-basic -n NewApp
  • cd NewApp

then:

$ # runs fine
$ dotnet build
$ # breaks
$ dotnet run
Unhandled Exception: System.DllNotFoundException: Unable to load shared library 'libX11.so.6' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: liblibX11.so.6.so: cannot open shared object file: No such file or directory
   at Avalonia.X11.XLib.XInitThreads()
   at Avalonia.X11.AvaloniaX11Platform.Initialize(X11PlatformOptions options) in D:\a\1\s\src\Avalonia.X11\X11Platform.cs:line 31
   at Avalonia.Controls.AppBuilderBase`1.Setup() in D:\a\1\s\src\Avalonia.Controls\AppBuilderBase.cs:line 302
   at Avalonia.Controls.AppBuilderBase`1.Start(AppMainDelegate main, String[] args) in D:\a\1\s\src\Avalonia.Controls\AppBuilderBase.cs:line 153
   at App.Program.Main(String[] args) in /home/usul/Github/Horatius/src/App/Main.fs:line 56

Also, this seems to be posted as an issue on nixpkgs on dotnet cannot find libX11.so.6.

This is the current shell.nix I’m using for now (dotnet-sdk is installed globally):

{ pkgs ? import ./pinned-nixpkgs.nix {} }:

pkgs.multiStdenv.mkDerivation {
  name = "dev-shell";

  buildInputs = with pkgs; [
    libgdiplus
    mono6
    xorg.libX11
  ];
}

Any way to do a shellHook so libX11 gets workings correctly? Or is this an issue with a missing 32-bit lib?

I’ve managed to solve this by setting LD_LIBRARY_PATH correctly in a shell.nix. My solution is posted in this issue if someone ever has a similar problem like this again.