2020-08-31 01:17:48 +02:00
|
|
|
# based on the passed vscode will stdout a nix expression with the installed vscode extensions
|
2019-12-28 22:43:41 +01:00
|
|
|
{ lib
|
|
|
|
, vscodeDefault
|
|
|
|
, writeShellScriptBin
|
|
|
|
}:
|
2019-12-24 19:15:15 +01:00
|
|
|
|
|
|
|
##User input
|
2020-08-31 01:17:48 +02:00
|
|
|
{ vscode ? vscodeDefault
|
2019-12-28 22:43:41 +01:00
|
|
|
, extensionsToIgnore ? []
|
2019-12-24 19:15:15 +01:00
|
|
|
# will use those extensions to get sha256 if still exists when executed.
|
2020-08-31 01:17:48 +02:00
|
|
|
, extensions ? []
|
2019-12-24 19:15:15 +01:00
|
|
|
}:
|
2020-08-31 01:17:48 +02:00
|
|
|
let
|
2019-12-24 19:15:15 +01:00
|
|
|
mktplcExtRefToFetchArgs = import ./mktplcExtRefToFetchArgs.nix;
|
|
|
|
in
|
|
|
|
writeShellScriptBin "vscodeExts2nix" ''
|
2020-08-31 01:17:48 +02:00
|
|
|
echo '['
|
2019-12-24 19:15:15 +01:00
|
|
|
|
|
|
|
for line in $(${vscode}/bin/code --list-extensions --show-versions \
|
|
|
|
${lib.optionalString (extensionsToIgnore != []) ''
|
2020-08-31 01:17:48 +02:00
|
|
|
| grep -v -i '^\(${lib.concatMapStringsSep "\\|" (e : ''${e.publisher}.${e.name}'') extensionsToIgnore}\)'
|
2019-12-24 19:15:15 +01:00
|
|
|
''}
|
|
|
|
) ; do
|
|
|
|
[[ $line =~ ([^.]*)\.([^@]*)@(.*) ]]
|
|
|
|
name=''${BASH_REMATCH[2]}
|
|
|
|
publisher=''${BASH_REMATCH[1]}
|
|
|
|
version=''${BASH_REMATCH[3]}
|
|
|
|
|
|
|
|
extensions="${lib.concatMapStringsSep "." (e : ''${e.publisher}${e.name}@${e.sha256}'') extensions}"
|
|
|
|
reCurrentExt=$publisher$name"@([^.]*)"
|
|
|
|
if [[ $extensions =~ $reCurrentExt ]]; then
|
|
|
|
sha256=''${BASH_REMATCH[1]}
|
|
|
|
else
|
|
|
|
sha256=$(
|
|
|
|
nix-prefetch-url "${(mktplcExtRefToFetchArgs {publisher = ''"$publisher"''; name = ''"$name"''; version = ''"$version"'';}).url}" 2> /dev/null
|
|
|
|
)
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "{ name = \"''${name}\"; publisher = \"''${publisher}\"; version = \"''${version}\"; sha256 = \"''${sha256}\"; }"
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
|
|
echo ']'
|
|
|
|
''
|