···11+#! /usr/bin/env nix-shell
22+#! nix-shell -i bash -p curl jq unzip
33+# shellcheck shell=bash
44+set -eu -o pipefail
55+66+# can be added to your configuration with the following command and snippet:
77+# $ ./pkgs/applications/editors/vscode/extensions/update_installed_exts.sh > extensions.nix
88+#
99+# packages = with pkgs;
1010+# (vscode-with-extensions.override {
1111+# vscodeExtensions = map
1212+# (extension: vscode-utils.buildVscodeMarketplaceExtension {
1313+# mktplcRef = {
1414+# inherit (extension) name publisher version sha256;
1515+# };
1616+# })
1717+# (import ./extensions.nix).extensions;
1818+# })
1919+# ]
2020+2121+# Helper to just fail with a message and non-zero exit code.
2222+function fail() {
2323+ echo "$1" >&2
2424+ exit 1
2525+}
2626+2727+# Helper to clean up after ourselves if we're killed by SIGINT.
2828+function clean_up() {
2929+ TDIR="${TMPDIR:-/tmp}"
3030+ echo "Script killed, cleaning up tmpdirs: $TDIR/vscode_exts_*" >&2
3131+ rm -Rf "$TDIR/vscode_exts_*"
3232+}
3333+3434+function get_vsixpkg() {
3535+ N="$1.$2"
3636+3737+ # Create a tempdir for the extension download.
3838+ EXTTMP=$(mktemp -d -t vscode_exts_XXXXXXXX)
3939+4040+ URL="https://$1.gallery.vsassets.io/_apis/public/gallery/publisher/$1/extension/$2/latest/assetbyname/Microsoft.VisualStudio.Services.VSIXPackage"
4141+4242+ # Quietly but delicately curl down the file, blowing up at the first sign of trouble.
4343+ curl --silent --show-error --retry 3 --fail -X GET -o "$EXTTMP/$N.zip" "$URL"
4444+ # Unpack the file we need to stdout then pull out the version
4545+ VER=$(jq -r '.version' <(unzip -qc "$EXTTMP/$N.zip" "extension/package.json"))
4646+ # Calculate the SHA
4747+ SHA=$(nix-hash --flat --base32 --type sha256 "$EXTTMP/$N.zip")
4848+4949+ # Clean up.
5050+ rm -Rf "$EXTTMP"
5151+ # I don't like 'rm -Rf' lurking in my scripts but this seems appropriate.
5252+5353+ cat <<-EOF
5454+ {
5555+ name = "$2";
5656+ publisher = "$1";
5757+ version = "$VER";
5858+ sha256 = "$SHA";
5959+ }
6060+EOF
6161+}
6262+6363+# See if we can find our `code` binary somewhere.
6464+if [ $# -ne 0 ]; then
6565+ CODE=$1
6666+else
6767+ CODE=$(command -v code || command -v codium)
6868+fi
6969+7070+if [ -z "$CODE" ]; then
7171+ # Not much point continuing.
7272+ fail "VSCode executable not found"
7373+fi
7474+7575+# Try to be a good citizen and clean up after ourselves if we're killed.
7676+trap clean_up SIGINT
7777+7878+# Begin the printing of the nix expression that will house the list of extensions.
7979+printf '{ extensions = [\n'
8080+8181+# Note that we are only looking to update extensions that are already installed.
8282+for i in $($CODE --list-extensions)
8383+do
8484+ OWNER=$(echo "$i" | cut -d. -f1)
8585+ EXT=$(echo "$i" | cut -d. -f2)
8686+8787+ get_vsixpkg "$OWNER" "$EXT"
8888+done
8989+# Close off the nix expression.
9090+printf '];\n}'
···2929 sha256 = "sha256-vh7z8jupVxXPOko3sWUsOB7eji/7lKfwJ/CE3iw97Sw=";
3030 };
31313232- build-deps = nodePackages."rust-analyzer-build-deps-../../misc/vscode-extensions/rust-analyzer/build-deps";
3232+ build-deps = nodePackages."rust-analyzer-build-deps-../../applications/editors/vscode/extensions/rust-analyzer/build-deps";
3333 # FIXME: Making a new derivation to link `node_modules` and run `npm run package`
3434 # will cause a build failure.
3535 vsix = build-deps.override {
···11-#! /usr/bin/env nix-shell
22-#! nix-shell -i bash -p curl jq unzip
33-# shellcheck shell=bash
44-set -eu -o pipefail
55-66-# can be added to your configuration with the following command and snippet:
77-# $ ./pkgs/misc/vscode-extensions/update_installed_exts.sh > extensions.nix
88-#
99-# packages = with pkgs;
1010-# (vscode-with-extensions.override {
1111-# vscodeExtensions = map
1212-# (extension: vscode-utils.buildVscodeMarketplaceExtension {
1313-# mktplcRef = {
1414-# inherit (extension) name publisher version sha256;
1515-# };
1616-# })
1717-# (import ./extensions.nix).extensions;
1818-# })
1919-# ]
2020-2121-# Helper to just fail with a message and non-zero exit code.
2222-function fail() {
2323- echo "$1" >&2
2424- exit 1
2525-}
2626-2727-# Helper to clean up after ourselves if we're killed by SIGINT.
2828-function clean_up() {
2929- TDIR="${TMPDIR:-/tmp}"
3030- echo "Script killed, cleaning up tmpdirs: $TDIR/vscode_exts_*" >&2
3131- rm -Rf "$TDIR/vscode_exts_*"
3232-}
3333-3434-function get_vsixpkg() {
3535- N="$1.$2"
3636-3737- # Create a tempdir for the extension download.
3838- EXTTMP=$(mktemp -d -t vscode_exts_XXXXXXXX)
3939-4040- URL="https://$1.gallery.vsassets.io/_apis/public/gallery/publisher/$1/extension/$2/latest/assetbyname/Microsoft.VisualStudio.Services.VSIXPackage"
4141-4242- # Quietly but delicately curl down the file, blowing up at the first sign of trouble.
4343- curl --silent --show-error --retry 3 --fail -X GET -o "$EXTTMP/$N.zip" "$URL"
4444- # Unpack the file we need to stdout then pull out the version
4545- VER=$(jq -r '.version' <(unzip -qc "$EXTTMP/$N.zip" "extension/package.json"))
4646- # Calculate the SHA
4747- SHA=$(nix-hash --flat --base32 --type sha256 "$EXTTMP/$N.zip")
4848-4949- # Clean up.
5050- rm -Rf "$EXTTMP"
5151- # I don't like 'rm -Rf' lurking in my scripts but this seems appropriate.
5252-5353- cat <<-EOF
5454- {
5555- name = "$2";
5656- publisher = "$1";
5757- version = "$VER";
5858- sha256 = "$SHA";
5959- }
6060-EOF
6161-}
6262-6363-# See if we can find our `code` binary somewhere.
6464-if [ $# -ne 0 ]; then
6565- CODE=$1
6666-else
6767- CODE=$(command -v code || command -v codium)
6868-fi
6969-7070-if [ -z "$CODE" ]; then
7171- # Not much point continuing.
7272- fail "VSCode executable not found"
7373-fi
7474-7575-# Try to be a good citizen and clean up after ourselves if we're killed.
7676-trap clean_up SIGINT
7777-7878-# Begin the printing of the nix expression that will house the list of extensions.
7979-printf '{ extensions = [\n'
8080-8181-# Note that we are only looking to update extensions that are already installed.
8282-for i in $($CODE --list-extensions)
8383-do
8484- OWNER=$(echo "$i" | cut -d. -f1)
8585- EXT=$(echo "$i" | cut -d. -f2)
8686-8787- get_vsixpkg "$OWNER" "$EXT"
8888-done
8989-# Close off the nix expression.
9090-printf '];\n}'