nix-community / nix-vscode-extensions

Nix expressions for VSCode and OpenVSX extensions [maintainers: @deemp, @AmeerTaweel]
MIT License
223 stars 13 forks source link
openvsx vscode vscode-extension

Nix expressions for VS Code Extensions

At the time of writing this, nixpkgs contains 271 VS Code extensions. This is a small fraction of the more than 40,000 extensions in the VS Code Marketplace! In addition, many of the extensions in nixpkgs are significantly out-of-date.

This flake provides Nix expressions for the majority of available extensions from Open VSX and VS Code Marketplace. A GitHub Action updates the extensions daily.

That said, you can now use a different set of extensions for VS Code/VSCodium in each of your projects. Moreover, you can share your flakes and cache them so that other people don't need to install these extensions manually!

Note

Template

This repository has a flake template. This template provides a VSCodium with a couple of extensions.

  1. Create a flake from the template (see nix flake new).

    nix flake new vscodium-project -t github:nix-community/nix-vscode-extensions
    cd vscodium-project
    git init && git add .
  2. Run VSCodium.

    nix run .# .
  3. Alternatively, start a devShell and run VSCodium. A shellHook will print extensions available in the VSCodium.

    nix develop
    codium .

In case of problems see Troubleshooting.

Example

flake.nix provides a default package. This package is VSCodium with a couple of extensions.

Run VSCodium and list installed extensions.

nix run github:nix-community/nix-vscode-extensions# -- --list-extensions

Usage

Extensions

We provide extensions attrsets that contain both universal and platform-specific extensions. We use a reasonable mapping between the sites target platforms and Nix-supported platforms (see the issue and systemPlatform in flake.nix).

There are several attrsets:

[!NOTE] In with A; with B;, the attributes of B shadow the attributes of A. Keep in mind this property of with when writing with vscode-marketplace; with vscode-marketplace-release;. See With-expressions.

With flakes

See Template.

Add the following to your flake.nix (see Flakes).

inputs.nix-vscode-extensions.url = "github:nix-community/nix-vscode-extensions";

Without flakes

let
  system = builtins.currentSystem;
  extensions =
    (import (builtins.fetchGit {
      url = "https://github.com/nix-community/nix-vscode-extensions";
      ref = "refs/heads/master";
      rev = "c43d9089df96cf8aca157762ed0e2ddca9fcd71e";
    })).extensions.${system};
  extensionsList = with extensions.vscode-marketplace; [
      rust-lang.rust-analyzer
  ];
in ...

History

You can search for an extension in the repo history:

Explore

Explore extensions via nix repl.

Use your system instead of x86_64-linux.

Press the Tab button (denoted as <TAB> here) to see attrset attributes.

Get the extensions attrset

Get extensions with flakes

$ nix repl

nix-repl> :lf github:nix-community/nix-vscode-extensions/c43d9089df96cf8aca157762ed0e2ddca9fcd71e
Added 10 variables.

nix-repl> t = extensions.<TAB>
extensions.aarch64-darwin  extensions.aarch64-linux   extensions.x86_64-darwin   extensions.x86_64-linux

nix-repl> t = extensions.x86_64-linux

nix-repl> t.<TAB>
t.forVSCodeVersion            t.open-vsx-release            t.vscode-marketplace-release
t.open-vsx                    t.vscode-marketplace

Get extensions without flakes

$ nix repl

nix-repl> t1 = (import (builtins.fetchGit {
                url = "https://github.com/nix-community/nix-vscode-extensions";
                ref = "refs/heads/master";
                rev = "c43d9089df96cf8aca157762ed0e2ddca9fcd71e";
              }))

nix-repl> t = t1.extensions.<TAB>
t1.extensions.aarch64-darwin  t1.extensions.aarch64-linux   t1.extensions.x86_64-darwin   t1.extensions.x86_64-linux

nix-repl> t = t1.extensions.x86_64-linux

nix-repl> t.<TAB>
t.forVSCodeVersion            t.open-vsx-release            t.vscode-marketplace-release
t.open-vsx                    t.vscode-marketplace

Pre-release versions

nix-repl> t.vscode-marketplace.rust-lang.rust-analyzer
«derivation /nix/store/jyzab0pdcgj4q9l73zsnyvc1k7qpb381-vscode-extension-rust-lang-rust-analyzer-0.4.1582.drv»

Release versions

nix-repl> t.vscode-marketplace-release.rust-lang.rust-analyzer
«derivation /nix/store/qjlr7iqgqrf2hd2z21xz96nmblxy680m-vscode-extension-rust-lang-rust-analyzer-0.3.1583.drv»

Pre-release versions compatible with a given version of VS Code

nix-repl> (t.forVSCodeVersion "1.78.2").vscode-marketplace.rust-lang.rust-analyzer
«derivation /nix/store/jyzab0pdcgj4q9l73zsnyvc1k7qpb381-vscode-extension-rust-lang-rust-analyzer-0.4.1582.drv»

Overlay

See Overlays.

Get an overlay with flakes

nix-repl> :lf github:nix-community/nix-vscode-extensions/c43d9089df96cf8aca157762ed0e2ddca9fcd71e
Added 14 variables.

nix-repl> pkgs = (legacyPackages.x86_64-linux.extend overlays.default)

nix-repl> pkgs.vscode-marketplace-release.rust-lang.rust-analyzer
«derivation /nix/store/midv6wrnpxfm3in3miilyx914zzck4d7-vscode-extension-rust-lang-rust-analyzer-0.3.1575.drv»

Get an overlay without flakes

nix-repl> t1 = (import (builtins.fetchGit {
                url = "https://github.com/nix-community/nix-vscode-extensions";
                ref = "refs/heads/master";
                rev = "c43d9089df96cf8aca157762ed0e2ddca9fcd71e";
              }))

nix-repl> pkgs = import <nixpkgs> { overlays = [ t1.overlays.default ]; system = builtins.currentSystem; }

nix-repl> pkgs.vscode-marketplace-release.rust-lang.rust-analyzer
«derivation /nix/store/a701wlb8ckidpikr57bff16mmvsf3jir-vscode-extension-rust-lang-rust-analyzer-0.3.1575.drv»

Contribute

Issues

Resolve issues.

README

Release extensions

The config contains several extensions. We cache the information about the latest release versions of these extensions (see Extensions).

You can add new extensions to the config and make a Pull Request. Use the original extension publisher and name, e.g. GitHub and copilot.

Extra extensions

The extra-extensions.toml file contains a list of extensions to be fetched from sites other than VS Code Marketplace and Open VSX. These extensions replace ones fetched from VS Code Marketplace and Open VSX. Add necessary extensions there, preferrably, for all supported platforms (see Extensions). nvfetcher will fetch the latest release versions of these extensions and write configs to generated.nix.

Special extensions

Certain extensions require special treatment.

Provide functions to modify such extension in overrides.nix.

Optionally, create and link there issues explaining chosen override functions.

Overrides apply to a whole attrset of extensions, including Extra extensions.

Each override is applied to an argument of the buildVscodeMarketplaceExtension function.

Build problems

Main flake

  1. (Optionally) Install direnv, e.g., via nix profile install nixpkgs#direnv.

  2. Run a devshell. When prompted about extra-trusted-substituters answer y. This is to use binary caches.

    nix develop nix-dev/
  3. (Optionally) Start VSCodium with necessary extensions and tools.

    nix run nix-dev/#writeSettings
    nix run nix-dev/#codium .

Haskell script

  1. See the README.

  2. Set the environment.

    set -a
    source .env
  3. Run the script.

    nix run haskell/#updateExtensions

Pull requests

Pull requests are welcome!

Troubleshooting