How to set up non-nix VsCode paths with dev shells

I have VsCode installed on regular linux and want to use it with a nix development shell.

One of the plugins needs the path to the interpreter set so it can send code chunks to the interpreter interactively. E.g. the R VsCode extension uses the program radian for interactive usage. In the VsCode settings, I have

/home/michael/.local/bin/radian

setup as path, which would be reflected in settings.json as

    "r.rterm.linux": "/home/michael/.local/bin/radian",

But this is my global installation. The issue now is how to get this path to be dynamic to whatever the nix shell points to. Simply doing nix develop and then code . does not work. I tried to adapt the shellHook in flake.nix:

    shellHook = ''
      export VSCODE_RADIAN="$(which radian)"
    '';

and the idea would be that nix develop evaluates this and then I can do in the settings.json "r.rterm.linux": "${env:VSCODE_RADIAN}",, but this does not work.
Also if I open code . from nix develop, the terminal in VsCode does not inherit environment variables from the shellHook.

Has anyone worked around this, making VsCode paths dynamic to nix where VsCode expects static paths?

If your dev shell is installing radian, could you have your dev shell also generate a settings.json file local to the project (vscode does support that iirc), then you should be able to just use ${lib.getExe pkgs.radian} or similar when generating the settings.json and it will populate with the Nix store path. Then you don’t need to worry about setting environment variables and such.

Does r.rterm.linux have to be an absolute path? … Apparently. Huh. vscode-R/src/rTerminal.ts at c513febbb4257910dc96755628a93abc40b6bdcc · REditorSupport/vscode-R · GitHub

If nothing else, you could work around this by creating a shim script which calls into the nix shell, e.g. with bin/radian having something like:

#!/usr/bin/env sh
nix-shell --command radian

Looks like the working directory is the workspace folder.

My reading of the variables reference is that it works for some but not all settings.

env FOO=abc123 code . and printenv FOO in the terminal doesn’t work?

I don’t know if this will solve your problem but for my project I just generated a local .vscode directory (which should override global settings if I recall correctly?) whenever I entered my shell with all the correct nix paths and deleted it when I exited the shell. I did it here.