IUWUPUTGXRMPSV3BOIT5HY2YGBXGFB2EQ4VCUOGQIYE4VT5CS5NQC
XNGFJHLQT32DYH52PZRADH5EQDY7HRNEJ472IP4FNWL45NYO6LNAC
6TJTI7RQ5QVCBPW6BKPUL6XUFWUIMXH774UAFCHACDJQWDMPSZNQC
UIVGUJCHU6JKX6FSEVA553CNNMZAMTTLLNBWQEA4L43BECZND6BAC
LCU2Y6NLRNRKR4R2YHQH5G6LJXG4UZZOMFEV7C5B2BDQPC45E5YAC
ZRJNPDNXM2XBDKJH4I4WFFNGFVWGFDPWRKAICRN45CMYRR5VADZAC
66COC6TI5UGIYQMWHOTONDBSH63AQYAHYP5UKYZR65Y6VEVJIPZQC
#! /usr/bin/env nix-shell
#! nix-shell -i bash -p curl jq unzip
# shellcheck shell=bash
set -eu -o pipefail
# can be added to your configuration with the following command and snippet:
# $ ./pkgs/misc/vscode-extensions/update_installed_exts.sh > extensions.nix
#
# packages = with pkgs;
# (vscode-with-extensions.override {
# vscodeExtensions = map
# (extension: vscode-utils.buildVscodeMarketplaceExtension {
# mktplcRef = {
# inherit (extension) name publisher version sha256;
# };
# })
# (import ./extensions.nix).extensions;
# })
# ]
# Helper to just fail with a message and non-zero exit code.
function fail() {
echo "$1" >&2
exit 1
}
# Helper to clean up after ourselves if we're killed by SIGINT.
function clean_up() {
TDIR="${TMPDIR:-/tmp}"
echo "Script killed, cleaning up tmpdirs: $TDIR/vscode_exts_*" >&2
rm -Rf "$TDIR/vscode_exts_*"
}
function get_vsixpkg() {
N="$1.$2"
# Create a tempdir for the extension download.
EXTTMP=$(mktemp -d -t vscode_exts_XXXXXXXX)
URL="https://$1.gallery.vsassets.io/_apis/public/gallery/publisher/$1/extension/$2/latest/assetbyname/Microsoft.VisualStudio.Services.VSIXPackage"
# Quietly but delicately curl down the file, blowing up at the first sign of trouble.
curl --silent --show-error --fail -X GET -o "$EXTTMP/$N.zip" "$URL"
# Unpack the file we need to stdout then pull out the version
VER=$(jq -r '.version' <(unzip -qc "$EXTTMP/$N.zip" "extension/package.json"))
# Calculate the SHA
SHA=$(nix-hash --flat --base32 --type sha256 "$EXTTMP/$N.zip")
# Clean up.
rm -Rf "$EXTTMP"
# I don't like 'rm -Rf' lurking in my scripts but this seems appropriate.
cat <<-EOF
{
name = "$2";
publisher = "$1";
version = "$VER";
sha256 = "$SHA";
}
EOF
}
# See if we can find our `code` binary somewhere.
if [ $# -ne 0 ]; then
CODE=$1
else
CODE=$(command -v code || command -v codium)
fi
if [ -z "$CODE" ]; then
# Not much point continuing.
fail "VSCode executable not found"
fi
# Try to be a good citizen and clean up after ourselves if we're killed.
trap clean_up SIGINT
# Begin the printing of the nix expression that will house the list of extensions.
printf '{ extensions = [\n'
# Note that we are only looking to update extensions that are already installed.
for i in $($CODE --list-extensions)
do
OWNER=$(echo "$i" | cut -d. -f1)
EXT=$(echo "$i" | cut -d. -f2)
get_vsixpkg "$OWNER" "$EXT"
done
# Close off the nix expression.
printf '];\n}'
{ extensions = [
{
name = "nix-env-selector";
publisher = "arrterian";
version = "1.0.7";
sha256 = "0mralimyzhyp4x9q98x3ck64ifbjqdp8cxcami7clvdvkmf8hxhf";
}
{
name = "rust-analyzer";
publisher = "matklad";
version = "0.3.901";
sha256 = "q/2rhvqNYLixEeRxi/RzGiwLi61HRYK4OSI4dpgWpWE=";
}
{
name = "pretty-formatter";
publisher = "mblode";
version = "0.2.2";
sha256 = "1kdcxdvccf1fhg8lr8zwi5v7l2ja02p1kxq871jgakq2y42fclpy";
}
{
name = "cmake-tools";
publisher = "ms-vscode";
version = "1.9.2";
sha256 = "12r360fr38qq1cvssg0ajhhipcaymbdjjd9dncy4fb02ajha823s";
}
{
name = "cpptools";
publisher = "ms-vscode";
version = "1.7.1";
sha256 = "0hc6gnw00mri6hijm752zmhz26864dk8gxwa0yshy20hk9z29y6s";
}
{
name = "vsliveshare";
publisher = "ms-vsliveshare";
version = "1.0.5242";
sha256 = "0mndks2zfpxydd9fpwbi98qdhzkjzwfhh7hg3z222l18scfzad3z";
}
{
name = "cmake";
publisher = "twxs";
version = "0.0.17";
sha256 = "11hzjd0gxkq37689rrr2aszxng5l9fwpgs9nnglq3zhfa1msyn08";
}
{
name = "vim";
publisher = "vscodevim";
version = "1.21.10";
sha256 = "0c9m7mc2kmfzj3hkwq3d4hj43qha8a75q5r1rdf1xfx8wi5hhb1n";
}
{
name = "gruvbox";
publisher = "jdinhlife";
version = "1.5.1";
sha256 = "0ghB0E+Wa9W2bNFFiH2Q3pUJ9HV5+JfKohX4cRyevC8=";
}
];
}
[ ms-vscode.cpptools vscodevim.vim ]
++ pkgs.vscode-utils.extensionsFromVscodeMarketplace [
{
name = "pretty-formatter";
publisher = "mblode";
version = "0.2.2";
sha256 = "1kdcxdvccf1fhg8lr8zwi5v7l2ja02p1kxq871jgakq2y42fclpy";
}
{
name = "rust-analyzer";
publisher = "matklad";
version = "0.2.297";
sha256 = "0pj29k5pm1p7f987x9rjd0pks552fxvjv72dscxsk84svl132s0f";
}
{
name = "cmake-tools";
publisher = "ms-vscode";
version = "1.4.2";
sha256 = "1azjqd5w14q1h8z6cib4lwyk3h9hl1lzzrnc150inn0c7v195qcl";
}
{
name = "CMake";
publisher = "twxs";
version = "0.0.17";
sha256 = "11hzjd0gxkq37689rrr2aszxng5l9fwpgs9nnglq3zhfa1msyn08";
}
{
name = "nix-env-selector";
publisher = "arrterian";
version = "1.0.7";
sha256 = "0mralimyzhyp4x9q98x3ck64ifbjqdp8cxcami7clvdvkmf8hxhf";
}
{
name = "vsliveshare";
publisher = "ms-vsliveshare";
version = "1.0.4272";
sha256 = "0dhs9lkprz2q79kpkj2d22d09lvhl77n38vj0rsz80g9vj41jzwh";
}
];
[ ms-vscode.cpptools vscodevim.vim ];