# Environment beginner's question (dotNet)

**URL:** https://discourse.nixos.org/t/environment-beginners-question-dotnet/15517
**Category:** Help
**Created:** [October 16, 2021, 12:16am UTC](https://discourse.nixos.org/t/environment-beginners-question-dotnet/15517 "2021-10-16T00:16:04Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![Osiel](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/o/a587f6/32.png) [@Osiel](https://discourse.nixos.org/u/Osiel)
#### Post date: [October 16, 2021, 12:16am UTC](https://discourse.nixos.org/t/environment-beginners-question-dotnet/15517/1 "2021-10-16T00:16:04Z")

</div>

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

 ![image](https://discourse.nixos.org/uploads/default/original/2X/2/26f67943fb1b3a3252c4c22f6d5e62b1b748d6e4.png)

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](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

 ![image](https://discourse.nixos.org/uploads/default/original/2X/a/a6a4a514034eb54793512eb1b8bdb0353359622c.png)

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](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

---

<div class="post-metadata">

### Author: ![jonringer](https://discourse.nixos.org/user_avatar/discourse.nixos.org/jonringer/32/1348_2.png) [@jonringer](https://discourse.nixos.org/u/jonringer)
#### Post date: [October 16, 2021, 5:08am UTC](https://discourse.nixos.org/t/environment-beginners-question-dotnet/15517/2 "2021-10-16T05:08:24Z")

</div>

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](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)

---

<div class="post-metadata">

### Author: ![Osiel](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/o/a587f6/32.png) [@Osiel](https://discourse.nixos.org/u/Osiel)
#### Post date: [October 16, 2021, 10:05am UTC](https://discourse.nixos.org/t/environment-beginners-question-dotnet/15517/3 "2021-10-16T10:05:09Z")

</div>

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”](https://github.com/NixOS/nixpkgs/archive/596739026bbe0c693708119e5cd3e1b3aa88fd2d.tar.gz%E2%80%9D)

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

---

<div class="post-metadata">

### Author: ![jonringer](https://discourse.nixos.org/user_avatar/discourse.nixos.org/jonringer/32/1348_2.png) [@jonringer](https://discourse.nixos.org/u/jonringer)
#### Post date: [October 16, 2021, 4:02pm UTC](https://discourse.nixos.org/t/environment-beginners-question-dotnet/15517/4 "2021-10-16T16:02:33Z")

</div>

dotnetCorePackages.sdk\_2\_2 exists in unstable and 21.05, you want:

```auto
    with import {};

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

```

---

<div class="post-metadata">

### Author: ![Osiel](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/o/a587f6/32.png) [@Osiel](https://discourse.nixos.org/u/Osiel)
#### Post date: [October 17, 2021, 7:10pm UTC](https://discourse.nixos.org/t/environment-beginners-question-dotnet/15517/5 "2021-10-17T19:10:50Z")

</div>

Well!!!  
These are my nix-channel outputs both as user and sudo  
 ![image](https://discourse.nixos.org/uploads/default/original/2X/3/3e1b68c192f96bec316a960cb4b1e27dc37febaa.png)

Here is my file as per your guidance  
 ![image](https://discourse.nixos.org/uploads/default/original/2X/2/2da3f9655d2f7f41dce25e7305a7a1fb24b43ca1.png)

And this is the output when I run the file

 ![image](https://discourse.nixos.org/uploads/default/original/2X/0/00743458fc05dd4d3bd1c64274ed5aa8d9ffc474.png)

So I changed it to  
 ![image](https://discourse.nixos.org/uploads/default/original/2X/5/5f102cc73dbd7fe333819a3f988bac0c8e9f10a1.png)

And I got this output, could you tell me where I am going wrong  
 ![image](https://discourse.nixos.org/uploads/default/original/2X/7/7824fa59a8ab304dda1194859cf1e2d253913c69.png)

---

<div class="post-metadata">

### Author: ![Osiel](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/o/a587f6/32.png) [@Osiel](https://discourse.nixos.org/u/Osiel)
#### Post date: [October 19, 2021, 7:04pm UTC](https://discourse.nixos.org/t/environment-beginners-question-dotnet/15517/6 "2021-10-19T19:04:21Z")

</div>

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

 ![image](https://discourse.nixos.org/uploads/default/original/2X/0/0ddd82298c1b79a93755dfbeadf36c0c4ce194fb.png)

---

<div class="post-metadata">

### Author: ![jonringer](https://discourse.nixos.org/user_avatar/discourse.nixos.org/jonringer/32/1348_2.png) [@jonringer](https://discourse.nixos.org/u/jonringer)
#### Post date: [October 19, 2021, 7:15pm UTC](https://discourse.nixos.org/t/environment-beginners-question-dotnet/15517/7 "2021-10-19T19:15:24Z")

</div>

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).

---

<div class="post-metadata">

### Author: ![Osiel](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/o/a587f6/32.png) [@Osiel](https://discourse.nixos.org/u/Osiel)
#### Post date: [October 19, 2021, 7:32pm UTC](https://discourse.nixos.org/t/environment-beginners-question-dotnet/15517/8 "2021-10-19T19:32:11Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![jonringer](https://discourse.nixos.org/user_avatar/discourse.nixos.org/jonringer/32/1348_2.png) [@jonringer](https://discourse.nixos.org/u/jonringer)
#### Post date: [October 19, 2021, 8:32pm UTC](https://discourse.nixos.org/t/environment-beginners-question-dotnet/15517/9 "2021-10-19T20:32:33Z")

</div>

Here’s some documentation on overlays, and how to apply them: [Overlays - NixOS Wiki](https://nixos.wiki/wiki/Overlays#Overriding_a_version)

in your case, you want something like:

```auto
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.

---

<div class="post-metadata">

### Author: ![idjo](https://discourse.nixos.org/user_avatar/discourse.nixos.org/idjo/32/28223_2.png) [@idjo](https://discourse.nixos.org/u/idjo)
#### Post date: [June 23, 2024, 4:05pm UTC](https://discourse.nixos.org/t/environment-beginners-question-dotnet/15517/10 "2024-06-23T16:05:23Z")

</div>

Hi there, i manage to achieve this by using this shell.nix

```auto
let
  pkgs = (import (builtins.fetchTarball "https://github.com/NixOS/nixpkgs/archive/0f87b32eb18e4fe3d19aa40176abbb996354ca88.tar.gz") { });
in
pkgs.mkShell {
  buildInputs = [
    pkgs.dotnet-sdk_3
  ];
}

```

this is the result:

 ![image](https://discourse.nixos.org/uploads/default/original/3X/5/4/54687b97ca60fd829b2057005283aac2e69a8983.png)

hope it helps @Osiel
