VSCode remote/SSH developement: How do I make it automatically switch into the nix shell?

I would like to use VSCode to work on a project remotely (ssh) which uses nix flakes. This would require starting the VSCode remote server inside of the development shell, I think. I have looked into the “Nix Environment selector” plugin, but it does not support flakes (Although it might be possible to create a shell.nix which just calls the flake.nix).

Any help would be appreciated

you can use direnv and direnv-vscode to do this

and then you won’t have to start vscode inside of the development shell

do you guys know the exact steps to make this work?

  • I installed direnv on the server
  • I installer direnv-vscode (after SSH’ing, a number of vscode extension will ask me to install them on the SSH’ed server / reenable them it seems, don’t know if you have to do that here if you already have it)
  • I created a .envrc with use flake <NAME_OF_FLAKE>

specific to ocaml:

  • once I’m in the shell, I did which ocamlc and which ocamllsp and added both paths to the server’s .bashrc as export PATH="$PATH:<path1>:<path2>" (otherwise it seems like vscode ocamlplatform extension, which you need to reinstall on vscode as well, can’t find them)
  • when I SSH into the server, then go to the directory, and it works