Environment beginner's question (dotNet)

Hi guys!!!
I’m trying to migrate to NixOs and for that I set up an environment in VirtualBox. I would like to ask some questions.
Currently I use KDENeon and work with JetBrains Rider in C# in projects that need dotnet-sdk-2.2.401 and dotnet-sdk-5.0.401 I made the configuration in KdeNeon and try this result with dotNet --info

So the company project compiles normally. I am trying to set up this kind of environment in NixOs
My attempts so far have been

$ nix-env --preserve-installed -i dotnet-sdk-2.2.401 -f https://github.com/NixOS/nixpkgs/archive/596739026bbe0c693708119e5cd3e1b3aa88fd2d.tar.gz

$ nix-env --set-flag keep true dotnet-sdk-2.2.401

$ nix-env --preserve-installed -i dotnet-sdk

The result looks like the image below

I also tried something like (or vice versa)

$ nix-env --set-flag priority 5 dotnet-sdk
$ nix-env --set-flag priority 0 dotnet-sdk-2.2.401

And it didn’t work, so I tried via nix-shell, creating the shell.nix file

{ pkgs ? import (fetchTarball “https://github.com/NixOS/nixpkgs/archive/596739026bbe0c693708119e5cd3e1b3aa88fd2d.tar.gz”) {} }
pkgs.mkShell {
# nativeBuildInputs is usually what you want – tools you need to run
nativeBuildInputs = [ pkgs.dotnet-sdk ];
}

And then I call the rider inside my nix-shell and I still can’t compile the projects.
What would be the correct way to set up such an environment?
Inside my shell.nix is it possible to call two different tarballs installing different versions of the sdk package?

Thanks.
Sorry for any translation errors. I’m from Brazil

1 Like

You’ll want to look at https://github.com/NixOS/nixpkgs/blob/a613697d6e4e00ad3d239845a91ff2b06dcaecc8/doc/languages-frameworks/dotnet.section.md#using-many-sdks-in-a-workflow-using-many-sdks-in-a-workflow

1 Like

Right, I created the example shell.nix file containing the link and it is indeed what I need

with import {};

mkShell {
name = “dotnet-env”;
packages = [
(with dotnetCorePackages; combinePackages [
sdk_2_1
sdk_5_0
])
];
}

But it is still not clear how I can use the dotnet-sdk_2_2 version as it has been removed and I only found the 19.09 version specifically here

https://github.com/NixOS/nixpkgs/archive/596739026bbe0c693708119e5cd3e1b3aa88fd2d.tar.gz”

Sorry if it seems obvious how to do it but I still don’t understand about version that is not in nixpkgs.

Thank you very much for your help

dotnetCorePackages.sdk_2_2 exists in unstable and 21.05, you want:

    with import {};

    mkShell {
    name = “dotnet-env”;
    packages = [
    (with dotnetCorePackages; combinePackages [
    sdk_5_0
    sdk_2_2
    sdk_2_1
    ])
    ];
    }

Well!!!
These are my nix-channel outputs both as user and sudo
image

Here is my file as per your guidance
image

And this is the output when I run the file

So I changed it to
image

And I got this output, could you tell me where I am going wrong
image

With the show-trace command I got this answer could you give me some direction

I haven’t used dotnet since my last job. I think the correct course of action would be to create an overlay which adds it back.

IIRC, this should only be a blocker if you need sdk_2_2 to build a the package purely with nix. If you just need a dev environment, then the newer sdks should be able to retrieve in a way that’s compatible with nix (e.g. relative to home, not nix store binary).

I even tried to use 3.1 instead of 2.2 or 2.1 but the company’s project does not compile. I really need the 2.2 version.

About your suggestions could you give me more details on how to do.
As I said this is my first NixOS installation.

Here’s some documentation on overlays, and how to apply them: Overlays - NixOS Wiki

in your case, you want something like:

prev: final: {
  dotnetCorePackages = prev.dotnetCorePackages // {
     sdk_2_2 = sdk_2_1.overrideAttrs (oldAttrs: {
         src = oldAttrs.overrideAttrs (oldSrcAttrs: {
           sha256 = "...";
           url = "https://dotnetcli.azureedge.net/dotnet/Sdk/2.....-linux-x64.tar.gz";
         });
     });
  };
}

That should be roughly enough, I just wrote this by hand, so I probably made some typos.

Of course, the best fix would be to not use an EOL sdk.