Last active
December 13, 2019 15:31
-
-
Save countoren/b07757a8e39e8380c5978828fc2ef40b to your computer and use it in GitHub Desktop.
A nix function to bring vscode with extensions into a nix-shell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ pkgs ? import <nixpkgs> {} | |
, vscode-personal ? import ./vscode-personal.nix { inherit pkgs; } | |
}: | |
with pkgs; | |
let | |
les = [ | |
{ | |
name = "csharp"; | |
publisher = "ms-vscode"; | |
version = "1.21.5"; | |
sha256 = "031yx2kpjrw1b86y5nq110k9ywjgl26730ljddly05d8fxxham05"; | |
} | |
]; | |
lextensions = pkgs.vscode-utils.extensionsFromVscodeMarketplace les; | |
es = vscode-personal.extensions; | |
extensions = pkgs.vscode-utils.extensionsFromVscodeMarketplace es; | |
rmExtensions = '' | |
find exts -mindepth 1 -maxdepth 1 ${lib.concatMapStringsSep " " (e : ''! -iname ${e.publisher}.${e.name}'') (es++les)} -exec sudo rm -rf {} \; | |
''; | |
cpExtensions = '' | |
${lib.concatMapStringsSep "\n" (e : ''ln -sfn ${e}/share/vscode/extensions/* exts/'') extensions} | |
${lib.concatMapStringsSep "\n" (e : ''cp -a ${e}/share/vscode/extensions/* exts/'') lextensions} 2>/dev/null | |
''; | |
vc = writeShellScriptBin "code" '' | |
mkdir -p exts | |
${rmExtensions} | |
${cpExtensions} | |
${vscode}/bin/code --extensions-dir exts "$@" | |
''; | |
f = writeShellScript "f" '' | |
echo $1 | awk '{ print "https://"$2".gallery.vsassets.io/_apis/public/gallery/publisher/"$2"/extension/"$1"/"$3"/assetbyname/Microsoft.VisualStudio.Services.VSIXPackage" | |
''; | |
vce2nix = writeShellScriptBin "vscodeExts2nix" '' | |
echo '[' && | |
${vc}/bin/code --list-extensions --show-versions \ | |
| grep -v -i '^\(${lib.concatMapStringsSep "\\|" (e : ''${e.publisher}.${e.name}'') es}\)' \ | |
| perl -pe 's/^(.+?)\.(.+?)@(.*)/\1 \2 \3/' \ | |
| awk '{ print "{ name = "$1"; publisher = "$2"; version = "$3"; " }' \ | |
&& echo ']' | |
''; | |
# echo $i | \ | |
# awk '{ print "https://"$1".gallery.vsassets.io/_apis/public/gallery/publisher/"$1"/extension/"$2"/"$3"/assetbyname/Microsoft.VisualStudio.Services.VSIXPackage;" }' | nix-prefetch-url ; | |
# $(echo $i | awk '{ print "{ name = "$1"; publisher = "$2"; version = "$3"; " }')\ | |
# https://csharp.gallery.vsassets.io/_apis/public/gallery/publisher/csharp/extension/ms-vscode/1.21.5/assetbyname/Microsoft.VisualStudio.Services.VSIXPackage | |
in buildEnv { | |
name = "dfsf"; | |
paths = [ vce2nix vc ]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment