Use nix-build to manually install vscode extensions

I found that I can checkout nixpkgs repository and from the root of nixpkgs, do the following:

nix-build -A pkgs.vscode-extensions.dhall \
  --out-link ~/.vscode/extensions/dhall

however the problem is that the actual plugin ends up inside it’s own extensions folder:

~/.vscode/extensions/dhall/share/vscode/extensions/dhall.dhall-lang/

and unreachable from vscode. Then there is this hack, where you provide vscode as a nixos module, and you create an activation script:

  system.activationScripts.fix-vscode-extensions = {
            text = ''
                EXT_DIR=${config.vscode.homeDir}/.vscode/extensions
                mkdir -p $EXT_DIR
                chown ${config.vscode.user}:users $EXT_DIR
                for x in ${lib.concatMapStringsSep " " toString config.vscode.extensions}; do
                    ln -sf $x/share/vscode/extensions/* $EXT_DIR/
                done
                chown -R ${config.vscode.user}:users $EXT_DIR
            '';
            deps = [];
        };

I guess it is possible to provide your own module like this, but my experience with nixpkgs and vscode, is that things break quite often, having it as part of
nixos-rebuild switch often create problems.

It would be nice if it was possible to do some of these things manually, just using nix-build, also to test new packages and just update some of them at their own pace. Maybe flake is the solution. I haven’t had time to look into it yet.

Why don’t you use the vscodeWxtensions argument to vscode? Visual Studio Code - NixOS Wiki

It is related to this:

Using this will remove all existing extensions, not all packages are possible to use via nixpkgs, or it can be a lot of work to achieve that. I have been using the hack mentioned in this thread, but it is not always the best way either.

Sometimes I live on the edge, and I need to mix versions from different channels, and even do manual upgrade on some of the packages myself.

I found the best way for now, is to use vscode extensions directly from vscode, but sometimes you need nix to patch, and then nixpkgs is the only solution.

Thanks for the reminder though :slight_smile: It’s been a while since I tested that, so maybe it has been improved.