···1+#! /usr/bin/env nix-shell
2+#! nix-shell -i bash -p curl jq unzip
3+# shellcheck shell=bash
4+set -eu -o pipefail
5+6+# can be added to your configuration with the following command and snippet:
7+# $ ./pkgs/applications/editors/vscode/extensions/update_installed_exts.sh > extensions.nix
8+#
9+# packages = with pkgs;
10+# (vscode-with-extensions.override {
11+# vscodeExtensions = map
12+# (extension: vscode-utils.buildVscodeMarketplaceExtension {
13+# mktplcRef = {
14+# inherit (extension) name publisher version sha256;
15+# };
16+# })
17+# (import ./extensions.nix).extensions;
18+# })
19+# ]
20+21+# Helper to just fail with a message and non-zero exit code.
22+function fail() {
23+ echo "$1" >&2
24+ exit 1
25+}
26+27+# Helper to clean up after ourselves if we're killed by SIGINT.
28+function clean_up() {
29+ TDIR="${TMPDIR:-/tmp}"
30+ echo "Script killed, cleaning up tmpdirs: $TDIR/vscode_exts_*" >&2
31+ rm -Rf "$TDIR/vscode_exts_*"
32+}
33+34+function get_vsixpkg() {
35+ N="$1.$2"
36+37+ # Create a tempdir for the extension download.
38+ EXTTMP=$(mktemp -d -t vscode_exts_XXXXXXXX)
39+40+ URL="https://$1.gallery.vsassets.io/_apis/public/gallery/publisher/$1/extension/$2/latest/assetbyname/Microsoft.VisualStudio.Services.VSIXPackage"
41+42+ # Quietly but delicately curl down the file, blowing up at the first sign of trouble.
43+ curl --silent --show-error --retry 3 --fail -X GET -o "$EXTTMP/$N.zip" "$URL"
44+ # Unpack the file we need to stdout then pull out the version
45+ VER=$(jq -r '.version' <(unzip -qc "$EXTTMP/$N.zip" "extension/package.json"))
46+ # Calculate the SHA
47+ SHA=$(nix-hash --flat --base32 --type sha256 "$EXTTMP/$N.zip")
48+49+ # Clean up.
50+ rm -Rf "$EXTTMP"
51+ # I don't like 'rm -Rf' lurking in my scripts but this seems appropriate.
52+53+ cat <<-EOF
54+ {
55+ name = "$2";
56+ publisher = "$1";
57+ version = "$VER";
58+ sha256 = "$SHA";
59+ }
60+EOF
61+}
62+63+# See if we can find our `code` binary somewhere.
64+if [ $# -ne 0 ]; then
65+ CODE=$1
66+else
67+ CODE=$(command -v code || command -v codium)
68+fi
69+70+if [ -z "$CODE" ]; then
71+ # Not much point continuing.
72+ fail "VSCode executable not found"
73+fi
74+75+# Try to be a good citizen and clean up after ourselves if we're killed.
76+trap clean_up SIGINT
77+78+# Begin the printing of the nix expression that will house the list of extensions.
79+printf '{ extensions = [\n'
80+81+# Note that we are only looking to update extensions that are already installed.
82+for i in $($CODE --list-extensions)
83+do
84+ OWNER=$(echo "$i" | cut -d. -f1)
85+ EXT=$(echo "$i" | cut -d. -f2)
86+87+ get_vsixpkg "$OWNER" "$EXT"
88+done
89+# Close off the nix expression.
90+printf '];\n}'
···29 sha256 = "sha256-vh7z8jupVxXPOko3sWUsOB7eji/7lKfwJ/CE3iw97Sw=";
30 };
3132- build-deps = nodePackages."rust-analyzer-build-deps-../../misc/vscode-extensions/rust-analyzer/build-deps";
33 # FIXME: Making a new derivation to link `node_modules` and run `npm run package`
34 # will cause a build failure.
35 vsix = build-deps.override {
···29 sha256 = "sha256-vh7z8jupVxXPOko3sWUsOB7eji/7lKfwJ/CE3iw97Sw=";
30 };
3132+ build-deps = nodePackages."rust-analyzer-build-deps-../../applications/editors/vscode/extensions/rust-analyzer/build-deps";
33 # FIXME: Making a new derivation to link `node_modules` and run `npm run package`
34 # will cause a build failure.
35 vsix = build-deps.override {
···1-#! /usr/bin/env nix-shell
2-#! nix-shell -i bash -p curl jq unzip
3-# shellcheck shell=bash
4-set -eu -o pipefail
5-6-# can be added to your configuration with the following command and snippet:
7-# $ ./pkgs/misc/vscode-extensions/update_installed_exts.sh > extensions.nix
8-#
9-# packages = with pkgs;
10-# (vscode-with-extensions.override {
11-# vscodeExtensions = map
12-# (extension: vscode-utils.buildVscodeMarketplaceExtension {
13-# mktplcRef = {
14-# inherit (extension) name publisher version sha256;
15-# };
16-# })
17-# (import ./extensions.nix).extensions;
18-# })
19-# ]
20-21-# Helper to just fail with a message and non-zero exit code.
22-function fail() {
23- echo "$1" >&2
24- exit 1
25-}
26-27-# Helper to clean up after ourselves if we're killed by SIGINT.
28-function clean_up() {
29- TDIR="${TMPDIR:-/tmp}"
30- echo "Script killed, cleaning up tmpdirs: $TDIR/vscode_exts_*" >&2
31- rm -Rf "$TDIR/vscode_exts_*"
32-}
33-34-function get_vsixpkg() {
35- N="$1.$2"
36-37- # Create a tempdir for the extension download.
38- EXTTMP=$(mktemp -d -t vscode_exts_XXXXXXXX)
39-40- URL="https://$1.gallery.vsassets.io/_apis/public/gallery/publisher/$1/extension/$2/latest/assetbyname/Microsoft.VisualStudio.Services.VSIXPackage"
41-42- # Quietly but delicately curl down the file, blowing up at the first sign of trouble.
43- curl --silent --show-error --retry 3 --fail -X GET -o "$EXTTMP/$N.zip" "$URL"
44- # Unpack the file we need to stdout then pull out the version
45- VER=$(jq -r '.version' <(unzip -qc "$EXTTMP/$N.zip" "extension/package.json"))
46- # Calculate the SHA
47- SHA=$(nix-hash --flat --base32 --type sha256 "$EXTTMP/$N.zip")
48-49- # Clean up.
50- rm -Rf "$EXTTMP"
51- # I don't like 'rm -Rf' lurking in my scripts but this seems appropriate.
52-53- cat <<-EOF
54- {
55- name = "$2";
56- publisher = "$1";
57- version = "$VER";
58- sha256 = "$SHA";
59- }
60-EOF
61-}
62-63-# See if we can find our `code` binary somewhere.
64-if [ $# -ne 0 ]; then
65- CODE=$1
66-else
67- CODE=$(command -v code || command -v codium)
68-fi
69-70-if [ -z "$CODE" ]; then
71- # Not much point continuing.
72- fail "VSCode executable not found"
73-fi
74-75-# Try to be a good citizen and clean up after ourselves if we're killed.
76-trap clean_up SIGINT
77-78-# Begin the printing of the nix expression that will house the list of extensions.
79-printf '{ extensions = [\n'
80-81-# Note that we are only looking to update extensions that are already installed.
82-for i in $($CODE --list-extensions)
83-do
84- OWNER=$(echo "$i" | cut -d. -f1)
85- EXT=$(echo "$i" | cut -d. -f2)
86-87- get_vsixpkg "$OWNER" "$EXT"
88-done
89-# Close off the nix expression.
90-printf '];\n}'