NixOS in WSL - how to install VScode extensions

I successfully installed VS Code Remote inside my WSL NixOS by following this guide: https://nix-community.github.io/NixOS-WSL/how-to/vscode.html. All good there.

I can manually install extensions using the VS Code UI, which is also fine. But I’d like the setup to be reproducible.

The guide about VS Code on the NixOS wiki (https://nixos.wiki/wiki/Visual_Studio_Code) only mentions configuring extensions in programs.vscode, which doesn’t apply in WSL.

How can I install the extensions so that they’re ready after running home-manager switch?

I know I could probably do it with home.file.".vscode-server/extensions/extensions.json" by putting the whole JSON there, but that would make it hard to update and add new extensions over time.

What would you recommend?

Thank you.

1 Like

I don’t know anything like that for the remote server.

Looking for this as well.

For now, I just add the extensions to workspace recommendations. Then, when i switch to WSL, it asks me once if i would like to install the recommended extensions in WSL.

Going out of WSL and even when running nixos-rebuild preserves my installed extensions in NixOS, so it’s really a click-once and get over with it. Although i understand it isn’t really a NixOS mindset to do it like this.

You can also set remote.extensionKind in your .vscode/settings.json, to steer your extensions to the workspace (remote) instead of ui, but it doesn’t really help much in this case:

 "remote.extensionKind": {
        "arrterian.nix-env-selector": [
            "workspace"
        ],
        "jnoortheen.nix-ide": [
            "workspace"
        ]
    }

Maybe something like nix4vscode could solve this, please see deprecate nix-vscode-extensions in favor of nix4vscode · Issue #47 · nix-community/nix-vscode-extensions as well. For me that still feels too primitive.

2 Likes

I was looking for a solution for this as well and currently have somewhat of a workaround.

programs.vscode will write settings to ~/config/Code.
Meanwhile when working on WSL, the remote code server will work with settings/extensions in ~/.vscode-server/extensions. So i just symlink them for now:

home.file.".vscode-server/data/Machine/settings.json".source = config.lib.file.mkOutOfStoreSymlink "${config.xdg.configHome}/Code/User/settings.json";
home.file.".vscode-server/extensions".source = config.lib.file.mkOutOfStoreSymlink "${config.home.homeDirectory}/.vscode/extensions";

Probably not the cleanest solution, but works well enough for me.

2 Likes