Are VS Code extensions broken?

I’ve put vscode and vscode-extensions.ms-vscode.cpptools 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 vscode-extensions.ms-python.python.

(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, ... }:

let
  extensions = (with pkgs.vscode-extensions; [
    arrterian.nix-env-selector
    bbenoist.nix
    brettm12345.nixfmt-vscode
    coolbear.systemd-unit-file
    davidanson.vscode-markdownlint
    # ...
  ]) ++ pkgs.vscode-utils.extensionsFromVscodeMarketplace [
    {
      name = "emacs-mcx";
      publisher = "tuttieee";
      version = "0.36.0";
      sha256 =
        "681fdca1e1c2e5ee2b25d3ad229e53f40607c976ba0f0a0c8bf2cec6345c4d91";
    }
    # {...}
  ];

  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 search.nixos.org
  • 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 = [
    ./hardware-configuration.nix
    # ...
    ./common/vscode.nix
  ];

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.