Problem combining multiple dotnet SDKs in usable flake

So I want to combine multiple dotnet SDKs in a flake. Roughly, I tried this:

{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs";
    flake-utils.url = "github:numtide/flake-utils";
  };
  outputs = { self, nixpkgs, flake-utils }:
    let
      pkgs = nixpkgs.legacyPackages."x86_64-linux";
    in flake-utils.lib.eachDefaultSystem (system: {
      packages.default = pkgs.buildEnv {
        name = "combined-dotnet";
        paths = with pkgs;
          [
            (with dotnetCorePackages;
              combinePackages [
                dotnetCorePackages.sdk_6_0
                dotnetCorePackages.sdk_7_0
                dotnetPackages.Nuget
              ])
          ];
      };
    });
}

This builds fabulously and the dotnet command works for dotnet 7 project. However, if I try a dotnet 6 project, I get an error roughly like this:

Failed to load dotnet-sdk-6.0.412 libcoreclr.so
error: /lib/x86_64-linux-gnu/libstdc++.so.6: version `GLIBCXX_3.4.3

Generally, I want to build a package to combine dotnet SDKs so that both of the SDKs are listed when you do dotnet --list-sdks or dotnet --info, which works. But the dotnet 6 SDK does not work as I just described.

Generally you can install multiple dotnet SDKs manually or with Microsofts helper scripts. They then have some common directories that put an extra directory with the version number of the SDKs and a single shared dotnet command can find all SDKs then.

What did I do incorrectly that causes me to get this error? To me, combinePackages appeared to be the solution I was looking for, but I get the loading error as described.

I found out a bit more. So I build my flake on Ubuntu, which lead to the problems I described.

However, if I enter a Docker container based on nix, I can build the flake without the problems I desribed.

Can someone explain how and why I have the problem if I call nix build on Ubuntu? I thought flakes were reproducible. I don’t have LD_LIBRARY_PATH or anything set like that. What is going on?

What is the full nix build command you’re running? Are you using --impure by chance?

Not, not to my knowledge. I just called nix build. Not args or special environment variables.

Just to let anyone who finds this know, I got a friendly reply from Reddit where I also posted the question.

This works:

{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs";
    flake-utils.url = "github:numtide/flake-utils";
  };
  outputs = {
    self,
    nixpkgs,
    flake-utils,
  }:
    flake-utils.lib.eachDefaultSystem (system: let
      pkgs = nixpkgs.legacyPackages.${system};
    in {
      packages.combinedSdk = pkgs.buildEnv {
        name = "combinedSdk";
        paths = [
          (with pkgs.dotnetCorePackages;
            combinePackages [
              sdk_6_0
              sdk_7_0
            ])
        ];
      };
    });
}

If anyone wants to add any details what I originally did wrong, you can.

1 Like