arrterian / nix-env-selector

Allows switch environment for Visual Studio Code using Nix Package Manager.
MIT License
220 stars 29 forks source link

No longer applies shell.nix to integrated terminal? #76

Open devmattrick opened 1 year ago

devmattrick commented 1 year ago

Describe the bug I'm not sure if this is caused by the VSCode update that came out recently, but I noticed that the shell.nix file no longer seems to be being applied to the integrated terminal. I noticed it after updating to the most recent version but it could also be unrelated to that.

To Reproduce Steps to reproduce the behavior:

  1. Open a project in VSCode containing a shell.nix file
  2. Load the environment using this Extension
  3. Open the integrated terminal in VSCode
  4. Try to use one of the executable files specified in shell.nix
  5. Note that the executables are not found
  6. Run nix-shell ./shell.nix
  7. Note that the executables are now available in the terminal

Expected behavior The integrated terminal should load with the executables (and libraries) provided in shell.nix.

Screenshots N/A

Environment:

Additional context N/A

sheepman4267 commented 1 year ago

Tried the extension for the first time last night and found it very strange that the terminal wasn't affected by the nix environment. Glad to see this might be unintentional.

Zaczero commented 1 year ago

I have found a temporary workaround for those who are using launch.json.

Perhaps it is possible to find a similar solution for a global case, but for me, launch.json fix is enough.

Basically, all you need to do is manually pass the $PATH environment:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "My Project",

            // ...

            "env": {
                "PATH": "${env:PATH}",
            },

            // ...
        }
    ]
}

Edit: This worked with Python module launch but not with Python file launch. This may not work in all scenarios.


For a global solution you could automatically enter nix-shell if present in the current directory.

An example using .zshrc:

if [ -f ./shell.nix ]; then
  if [ -z "$IN_NIX_SHELL" ]; then
    nix-shell
  fi
fi