Are VS Code extensions broken?

I’ve put vscode and into my configuration.nix, done nixos-rebuild switch and even rebooted.

However, attempting to “Run without debugging” C++ code in VS Code still asks me to install cpptools (which is also not happening)

Same with Python and

(Disclaimer: I used Visual Studio many moons ago, but I never really used VS Code, so maybe I’m making some silly mistake here)

There areseveral options.described in the wiki: Visual Studio Code - NixOS Wiki

I use the following method from there… (simplified)

{ pkgs, ... }:

  extensions = (with pkgs.vscode-extensions; [
    # ...
  ]) ++ pkgs.vscode-utils.extensionsFromVscodeMarketplace [
      name = "emacs-mcx";
      publisher = "tuttieee";
      version = "0.36.0";
      sha256 =
    # {...}

  vscode-with-extensions =
    pkgs.vscode-with-extensions.override { vscodeExtensions = extensions; };

in {
  config = { environment.systemPackages = [ vscode-with-extensions ]; };
1 Like

I’d seen that web site, and thought all that complexity was for some fringe unsupported extensions, not something as mainstream as C++ and Python.

There are two sets in the list above:

  • at the top, extensions that are packaged directly by nix, just by name. Find these at
  • the more explicit version, in the second part as a list of attrsets, for some of the more “fringe” ones that haven’t been imported to nix (or where you want a specific version)

When I copy this file to ~/.config/nixpkgs/home.nix and run home-manager switch, I get an error:

error: The option `environment' does not exist. Definition values:

That snippet above is a system level configuration, for HM the most equivalent option is home.packages.

If I use it in /etc/nixos/configuration.nix, I get a type error: (attempting to call something which is not a function but a set) here:

in {

Which sounds a bit as if you just blindly copy pasted to the end without properly inserting pieces where they belong.

That config above can be put in a file (say vscode.nix). I use it like this in my configuration for hosts that should have vscode:

  imports = [
    # ...

Note that if you don’t want to declare your extensions in your Nix config you can use vscode-fhs.

Personally I think having them in my configuration is better, just putting that out there if you’re too annoyed by having to do that.