Vscode remote development on NixOS

Has anyone configured a NixOS box to serve as a host for vscode remote development yet?


Please post here if you have found anything!

I haven’t dug into this too much yet, but it looks like vscode installs a bunch of binaries on the remote server under the users account. This might not be trivial to get working under nixos and unfortunately I haven’t had the time to work on it yet. Very unfortunate as this would be high value to me.

If any vscode on nixos gurus are reading please shed any insight you can.


Thank you for your reply, yes, I will post anything I find!

Has anyone tried doing this? From reading the docs it seems like it should work without much trouble.

NixOS tends to have trouble running unpatched binaries. One of my devs tried without success but I can’t recall the error he reported. I’ll follow up and post the error here later today.

you should probably ping Geoffrey: https://twitter.com/GeoffreyHuntley/status/1143064069244506112

1 Like

Why don’t you open an issue upstream requesting the source code to compile the binaries? It is ofc up to you but IMO putting any minute into the closed source parts of VS code is not worth the time.

I’ve tried a few combinations of this so far. Attached you’ll find some configurations from my current iteration which is an ubuntu box with nix which would work 1:1 on a nixos machine after converting below to expressions.

  1. Take the vouch configuration above, combine with GitHub - vouch/vouch-proxy: an SSO and OAuth / OIDC login solution for Nginx using the auth_request module , configure it to authenticate with GitHub oauth and run as a docker container.
  2. Take the above nginx configuration (adapt to a nix expression as need be) which denies unauthenticated requests and redirects to vouch.
  3. Take the above docker configuration of GitHub - cdr/code-server: VS Code in the browser and adapt it.

Enjoy. If you want to remove docker from the equation and build up an end-to-end nix expression of above (share it if you do) then use GitHub - nix-community/yarn2nix: Generate nix expressions from a yarn.lock file [maintainer=???] with GitHub - cdr/code-server: VS Code in the browser.

1 Like

The other combination that’s worth checking out is how I’m shipping nix w/vscode (mac, windows and linux) seamlessly to evaporate getting started friction w/learning haskell. Pull down this PR make learning haskell silky smooth with zero friction by ghuntley · Pull Request #340 · system-f/fp-course · GitHub and/or just click this link Dashboard — Gitpod

and finally using vscode (desktop) and the remote feature to a nixos server wasn’t working last time I checked. See please use #!/usr/bin/env bash instead of /bin/bash (which often doesn't exist!) · Issue #124 · microsoft/vscode-remote-release · GitHub

The latest release has fixed the above issue and resolved issues w/alpine containers meaning in theory up can use the .devcontainer/Dockerfile feature with GitHub - nix-community/docker-nix: Docker image for nix [maintainer=@zimbatm] [status=deprecated] or connect to a remote nixos server. I haven’t revisited this yet. Report back :slight_smile:

Thank you for your detailed response! I am busy with other tasks right now but let me try once I get to other things done.

1 Like

It looks like there is a solution to this problem: Does not work if target is a nixos · Issue #648 · microsoft/vscode-remote-release · GitHub

A big thank you to @simonchatts for looking into this and coming up with a workaround. Hopefully @wmertens comment in the thread will receive a bit more attention so we can get a proper solution, instead of a workaround.


I just tried the solution proposed by @simonchatts and it worked on my server.

Just a reminder, with the latest VSCode insiders, just replace node-10_x with node-12_x.

I’ll put what @simonchatts workaround here just in case someone doesn’t want to open GitHub.

For people just trying to get this working, the following works for me:

1. On the NixOS server, rm -rf ~/.vscode-server and ensure nodejs-10_x is installed (and no other nodejs version)

2. Try to initiate a remote session to the server from VSCode

3. After that fails, cd to ~/.vscode-server/bin/* on the server, and run rm node; ln -s $(which node)

4. Try to initiate a remote session again - should work this time

Slightly off-topic. When I use a Nix-provided vscode on Ubuntu with an ssh provided by Ubuntu, then when I attempt to use the Remote SSH plugin, it complains it cannot find ssh on PATH. Does this sound familiar?

What if development is done inside a nix-shell or FHS (for example anaconda) environment? Can this work with remote VS Code?

This is one potential solution I thought of and mentioned in one of the issues. If we create a FHS and then set that as the users shell then potentially vscode remote could work. There are some obvious down sides to this, but in my scenario I think this solution would be acceptable. I was actually planning on trying this in the next few weeks. I’ll report back.

thanks, that fix works as long as the version of vscode is not changing!

Did anybody come up with a permanent solution? I’m using insiders, hence I would have to patch this very regularly…

I briefly tried the FHS solution and while it appeared to work after some serious hackery I decided that was a horrible solution and am back to disappointing my developers by telling them to use this workaround after every update.

I’m subscribed to the relevant vscode issues, but still no real solution… :disappointed: