Dotnet run - error while loading shared libraries:

I’m attempting to build & run a .NET Core 3.1 app on NixOS 22.05. I used the supplied dotnet nix-shell script documented in the manual, with some extra library packages:

with import <nixpkgs> {};

mkShell {
  name = "dotnet-env";
  packages = [
    (with dotnetCorePackages; combinePackages [

The compile failed initially due to the nuget-managed protoc so I added this to my system after some googling:

  system.activationScripts.ldso = lib.stringAfter [ "usrbinenv" ] ''
            mkdir -m 0755 -p /lib64
            ln -sfn ${pkgs.glibc.out}/lib64/ /lib64/
            mv -f /lib64/ /lib64/ # atomically replace

dotnet run in GrpcGreeter fails

Now in nix-shell, compilation works with dotnet build. However, dotnet run while in GrpcGreeter fails with:

/home/bramford/git/ error while loading shared libraries: cannot open shared object file: No such file or directory

Using a buildFHSUserEnv shell also fails to run

I’ve also tried using nix-shell with buildFHSUserEnv as per fhs-shell.nix:

{ pkgs ? import <nixpkgs> {} }:

(pkgs.buildFHSUserEnv {
  name = "dotnet";

  targetPkgs = pkgs: [
    (with pkgs.dotnetCorePackages; combinePackages [


But it fails during dotnet run with:

A fatal error occurred. The required library could not be found.
If this is a self-contained application, that library should exist in [/home/bramford/git/].
If this is a framework-dependent application, install the runtime in the global location [/usr/share/dotnet] or use the DOTNET_ROOT environment variable to specify the runtime location or register the runtime location in [/etc/dotnet/install_location].

The .NET Core runtime can be found at:
dotnet-chrootenv:bramford@droop:~/git/$ ^C