Unable to Remove Old Generations

Something is keeping me from deleting old generations

As I run this command

csharp-ls
It was not possible to find any compatible framework version
The framework 'Microsoft.NETCore.App', version '7.0.0' (x64) was not found.
  - The following frameworks were found:
      6.0.5 at [/nix/store/nvh88588iypwkxjvacm4x3vrldw6h895-dotnet-sdk-6.0.300/shared/Microsoft.NETCore.App]

You can resolve the problem by installing the specified framework and/or SDK.

The specified framework can be found at:
  - https://aka.ms/dotnet-core-applaunch?framework=Microsoft.NETCore.App&framework_version=7.0.0&arch=x64&rid=nixos.22.05-x64

There is some old dotnet hanging around.

$dotnet --list-sdks
7.0.302 [/nix/store/83siv6hfnvdnl2axmzc6yvkfv6i1cn7x-dotnet-sdk-7.0.302/sdk]
$ dotnet --list-runtimes
Microsoft.AspNetCore.App 7.0.5 [/nix/store/83siv6hfnvdnl2axmzc6yvkfv6i1cn7x-dotnet-sdk-7.0.302/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 7.0.5 [/nix/store/83siv6hfnvdnl2axmzc6yvkfv6i1cn7x-dotnet-sdk-7.0.302/shared/Microsoft.NETCore.App]
[b0ef@spartacus:~]$

I try to find the reason

sudo nix-store --query --roots /nix/store/nvh88588iypwkxjvacm4x3vrldw6h895-dotnet-sdk-6.0.300
[sudo] password for b0ef:
/nix/var/nix/profiles/per-user/b0ef/profile-5-link -> /nix/store/vb26z9bn1szqnc1sk3cyr6fwiqv6dkya-user-environment
/nix/var/nix/gcroots/per-user/b0ef/current-home -> /nix/store/a48h7fwr01wqxlpq0am0lhlp1f7238li-home-manager-generation
/nix/var/nix/profiles/per-user/b0ef/home-manager-8-link -> /nix/store/a48h7fwr01wqxlpq0am0lhlp1f7238li-home-manager-generation
/proc/8008/environ -> /nix/store/nvh88588iypwkxjvacm4x3vrldw6h895-dotnet-sdk-6.0.300
/proc/8007/environ -> /nix/store/nvh88588iypwkxjvacm4x3vrldw6h895-dotnet-sdk-6.0.300
/proc/3425/environ -> /nix/store/nvh88588iypwkxjvacm4x3vrldw6h895-dotnet-sdk-6.0.300
/proc/4361/environ -> /nix/store/nvh88588iypwkxjvacm4x3vrldw6h895-dotnet-sdk-6.0.300
/proc/4507/environ -> /nix/store/nvh88588iypwkxjvacm4x3vrldw6h895-dotnet-sdk-6.0.300
/proc/31012/environ -> /nix/store/nvh88588iypwkxjvacm4x3vrldw6h895-dotnet-sdk-6.0.300
/proc/4428/environ -> /nix/store/nvh88588iypwkxjvacm4x3vrldw6h895-dotnet-sdk-6.0.300
/proc/21438/environ -> /nix/store/nvh88588iypwkxjvacm4x3vrldw6h895-dotnet-sdk-6.0.300
/proc/8009/environ -> /nix/store/nvh88588iypwkxjvacm4x3vrldw6h895-dotnet-sdk-6.0.300
/proc/4451/environ -> /nix/store/nvh88588iypwkxjvacm4x3vrldw6h895-dotnet-sdk-6.0.300
/proc/3424/environ -> /nix/store/nvh88588iypwkxjvacm4x3vrldw6h895-dotnet-sdk-6.0.300
/proc/3426/environ -> /nix/store/nvh88588iypwkxjvacm4x3vrldw6h895-dotnet-sdk-6.0.300
/proc/21497/environ -> /nix/store/nvh88588iypwkxjvacm4x3vrldw6h895-dotnet-sdk-6.0.300
/proc/21373/environ -> /nix/store/nvh88588iypwkxjvacm4x3vrldw6h895-dotnet-sdk-6.0.300
/proc/9306/environ -> /nix/store/nvh88588iypwkxjvacm4x3vrldw6h895-dotnet-sdk-6.0.300
/proc/3364/environ -> /nix/store/nvh88588iypwkxjvacm4x3vrldw6h895-dotnet-sdk-6.0.300
/proc/31029/environ -> /nix/store/nvh88588iypwkxjvacm4x3vrldw6h895-dotnet-sdk-6.0.300
/proc/9259/environ -> /nix/store/nvh88588iypwkxjvacm4x3vrldw6h895-dotnet-sdk-6.0.300
/proc/9111/environ -> /nix/store/nvh88588iypwkxjvacm4x3vrldw6h895-dotnet-sdk-6.0.300
/proc/8173/environ -> /nix/store/nvh88588iypwkxjvacm4x3vrldw6h895-dotnet-sdk-6.0.300
/proc/9258/environ -> /nix/store/nvh88588iypwkxjvacm4x3vrldw6h895-dotnet-sdk-6.0.300
/proc/8019/environ -> /nix/store/nvh88588iypwkxjvacm4x3vrldw6h895-dotnet-sdk-6.0.300
/proc/31010/environ -> /nix/store/nvh88588iypwkxjvacm4x3vrldw6h895-dotnet-sdk-6.0.300
/proc/3365/environ -> /nix/store/nvh88588iypwkxjvacm4x3vrldw6h895-dotnet-sdk-6.0.300
/proc/3366/environ -> /nix/store/nvh88588iypwkxjvacm4x3vrldw6h895-dotnet-sdk-6.0.300
/proc/2375/maps -> /nix/store/3rnfzdpgs1ppsbppwxf9na9yzm624y7v-home-manager-path
/proc/4361/maps -> /nix/store/3rnfzdpgs1ppsbppwxf9na9yzm624y7v-home-manager-path
/proc/9499/maps -> /nix/store/3rnfzdpgs1ppsbppwxf9na9yzm624y7v-home-manager-path
/proc/18884/maps -> /nix/store/3rnfzdpgs1ppsbppwxf9na9yzm624y7v-home-manager-path

Not sure I really understand the output of this;)

I’ve run many times

nix-collect-garbage -d

ok, it seems as if home-manager, this

    DOTNET_ROOT = "${pkgs.dotnet-sdk}";

is holding on to it.

Not sure why this returns an old dotnet.

Any pointers as to what is keeping dotnet-6 around?

Running processes.

All the /proc/*/environ listed there are running processes, that have an environment variable referencing the given path.

That variable is probably DOTNET_ROOT.

As you have already rebuilt and did a --delete-old GC (which is rarely what you want and ever rarer something you actually need) it should be fine to reboot, to get all varaibles pointing to the correct location. Then the old SDK location will be collectable. But you actually do not need to, as dotnet shouldn’t “see” or consider it anymore unless it keeps some state in its own config and cache files.