В NixOS можно настроить установку VSCode сразу с необходимыми расширениями.

Попробовав несколько разных вариантов я остановился на такой конфигурации:

  • все необходимые расширения описываются в json файле
  • скрипт для обновления расширений
  • и собственно конфиг
 1{ config, pkgs, lib, ... }:
 2
 3let
 4  unstable = import <unstable> { config.allowUnfree = true; };
 5
 6  # пусть до файла со списком раширений
 7  vscode_ext = lib.importJSON "/etc/nixos/configs/vscode.json";
 8  extensions =
 9    unstable.vscode-utils.extensionsFromVscodeMarketplace vscode_ext; # [
10  vscode-with-extensions =
11    unstable.vscode-with-extensions.override { vscodeExtensions = extensions; };
12in {
13  # Доп пакеты необходимые для расширений работы расширений
14  environment.systemPackages = with pkgs; [
15    vscode-with-extensions
16    graphviz
17    plantuml
18    adoptopenjdk-jre-bin
19  ];
20}

Пример json файла с парой расширений.

 1[
 2  {
 3    "name": "EditorConfig",
 4    "publisher": "EditorConfig",
 5    "version": "0.16.4",
 6    "sha256": "0fa4h9hk1xq6j3zfxvf483sbb4bd17fjl5cdm3rll7z9kaigdqwg"
 7  },
 8  {
 9    "name": "Nix",
10    "publisher": "bbenoist",
11    "version": "1.0.1",
12    "sha256": "0zd0n9f5z1f0ckzfjr38xw2zzmcxg1gjrava7yahg5cvdcw6l35b"
13  }
14]

Для обновления расширений можно можно использовать скрипт:

 1#!/usr/bin/env nix-shell
 2#!nix-shell -i bash -p curl jq unzip
 3set -eu -o pipefail
 4
 5# Helper to just fail with a message and non-zero exit code.
 6function fail() {
 7    echo "$1" >&2
 8    exit 1
 9}
10
11# Helper to clean up after ourself if we're killed by SIGINT
12function clean_up() {
13    TDIR="${TMPDIR:-/tmp}"
14    echo "Script killed, cleaning up tmpdirs: $TDIR/vscode_exts_*" >&2
15    rm -Rf "$TDIR/vscode_exts_*"
16}
17
18function get_vsixpkg() {
19    N="$1.$2"
20
21    # Create a tempdir for the extension download
22    EXTTMP=$(mktemp -d -t vscode_exts_XXXXXXXX)
23
24    URL="https://$1.gallery.vsassets.io/_apis/public/gallery/publisher/$1/extension/$2/latest/assetbyname/Microsoft.VisualStudio.Services.VSIXPackage"
25
26    # Quietly but delicately curl down the file, blowing up at the first sign of trouble.
27    curl --silent --show-error --fail -X GET -o "$EXTTMP/$N.zip" "$URL"
28    # Unpack the file we need to stdout then pull out the version
29    VER=$(jq -r '.version' <(unzip -qc "$EXTTMP/$N.zip" "extension/package.json"))
30    # Calculate the SHA
31    SHA=$(nix-hash --flat --base32 --type sha256 "$EXTTMP/$N.zip")
32
33    # Clean up.
34    rm -Rf "$EXTTMP"
35    # I don't like 'rm -Rf' lurking in my scripts but this seems appropriate
36
37    # cat <<-EOF
38  echo "{ \"name\": \"$2\", \"publisher\": \"$1\", \"version\": \"$VER\", \"sha256\": \"$SHA\" }"
39# EOF | jq -R .
40}
41
42# See if can find our code binary somewhere.
43if [ $# -ne 0 ]; then
44    CODE=$1
45else
46    CODE=$(command -v code)
47fi
48
49if [ -z "$CODE" ]; then
50    # Not much point continuing.
51    fail "VSCode executable not found"
52fi
53
54# Try to be a good citizen and clean up after ourselves if we're killed.
55trap clean_up SIGINT
56function main () {
57    # Begin the printing of the nix expression that will house the list of extensions.
58    # printf '[\n'
59
60    # Note that we are only looking to update extensions that are already installed.
61    for i in $($CODE --list-extensions)
62    do
63        OWNER=$(echo "$i" | cut -d. -f1)
64        EXT=$(echo "$i" | cut -d. -f2)
65
66        get_vsixpkg "$OWNER" "$EXT" | jq '.'
67    done
68    # Close off the nix expression.
69    # printf ']'
70}
71
72main | jq -s . | jq '.|=sort_by(.name)' > /etc/nixos/configs/vscode.json

Тем самым мы можем обновлять расширения не меняя основную конфигурацию nixos.