mwb
December 9, 2021, 4:26am
1
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)
uep
December 9, 2021, 5:01am
2
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
mwb
December 9, 2021, 5:08am
3
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.
uep
December 9, 2021, 5:14am
4
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)
mwb
December 9, 2021, 6:16am
5
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:
NobbZ
December 9, 2021, 6:27am
6
That snippet above is a system level configuration, for HM the most equivalent option is home.packages
.
mwb
December 9, 2021, 6:45am
7
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 {
NobbZ
December 9, 2021, 7:19am
8
Which sounds a bit as if you just blindly copy pasted to the end without properly inserting pieces where they belong.
uep
December 9, 2021, 8:33am
9
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
];
austin
December 11, 2021, 12:50am
10
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.