Merge pull request #28177 from jraygauthier/jrg/vscode-with-extensions

vscode-with-extensions: init at 1.10.2

authored by Joachim F and committed by GitHub 61aa2542 417c1ed4

+198
+82
pkgs/applications/editors/vscode-with-extensions/default.nix
··· 1 + { stdenv, lib, fetchurl, runCommand, buildEnv, vscode, which, writeScript 2 + , vscodeExtensions ? [] }: 3 + 4 + /* 5 + `vsixExtensions` 6 + : A set of vscode extensions to be installed alongside the editor. Here's a an 7 + example: 8 + 9 + ~~~ 10 + vscode-with-extensions.override { 11 + 12 + # When the extension is already available in the default extensions set. 13 + vscodeExtensions = with vscodeExtensions; [ 14 + nix 15 + ] 16 + 17 + # Concise version from the vscode market place when not available in the default set. 18 + ++ vscodeUtils.extensionsFromVscodeMarketplace [ 19 + { 20 + name = "code-runner"; 21 + publisher = "formulahendry"; 22 + version = "0.6.33"; 23 + sha256 = "166ia73vrcl5c9hm4q1a73qdn56m0jc7flfsk5p5q41na9f10lb0"; 24 + } 25 + ]; 26 + } 27 + ~~~ 28 + 29 + This expression should fetch 30 + - the *nix* vscode extension from whatever source defined in the 31 + default nixpkgs extensions set `vscodeExtensions`. 32 + 33 + - the *code-runner* vscode extension from the marketplace using the 34 + following url: 35 + 36 + ~~~ 37 + https://bbenoist.gallery.vsassets.io/_apis/public/gallery/publisher/bbenoist/extension/nix/1.0.1/assetbyname/Microsoft.VisualStudio.Services.VSIXPackage 38 + ~~~ 39 + 40 + The original `code` executable will be wrapped so that it uses the set of pre-installed / unpacked 41 + extensions as its `--extensions-dir`. 42 + */ 43 + 44 + let 45 + 46 + wrappedPkgVersion = lib.getVersion vscode; 47 + wrappedPkgName = lib.removeSuffix "-${wrappedPkgVersion}" vscode.name; 48 + 49 + combinedExtensionsDrv = buildEnv { 50 + name = "${wrappedPkgName}-extensions-${wrappedPkgVersion}"; 51 + paths = vscodeExtensions; 52 + }; 53 + 54 + wrappedExeName = "code"; 55 + exeName = wrappedExeName; 56 + 57 + wrapperExeFile = writeScript "${exeName}" '' 58 + #!${stdenv.shell} 59 + exec ${vscode}/bin/${wrappedExeName} \ 60 + --extensions-dir "${combinedExtensionsDrv}/share/${wrappedPkgName}/extensions" \ 61 + "$@" 62 + ''; 63 + 64 + in 65 + 66 + # When no extensions are requested, we simply redirect to the original 67 + # non-wrapped vscode executable. 68 + runCommand "${wrappedPkgName}-with-extensions-${wrappedPkgVersion}" { 69 + buildInputs = [ vscode which ]; 70 + dontPatchELF = true; 71 + dontStrip = true; 72 + meta = vscode.meta; 73 + } '' 74 + mkdir -p "$out/bin" 75 + ${if [] == vscodeExtensions 76 + then '' 77 + ln -sT "${vscode}/bin/${wrappedExeName}" "$out/bin/${exeName}" 78 + '' 79 + else '' 80 + ln -sT "${wrapperExeFile}" "$out/bin/${exeName}" 81 + ''} 82 + ''
+18
pkgs/misc/vscode-extensions/default.nix
··· 1 + { stdenv, lib, fetchurl, vscode-utils }: 2 + 3 + let 4 + inherit (vscode-utils) buildVscodeExtension buildVscodeMarketplaceExtension; 5 + in 6 + 7 + rec { 8 + nix = buildVscodeMarketplaceExtension { 9 + mktplcRef = { 10 + name = "nix"; 11 + publisher = "bbenoist"; 12 + version = "1.0.1"; 13 + sha256 = "0zd0n9f5z1f0ckzfjr38xw2zzmcxg1gjrava7yahg5cvdcw6l35b"; 14 + }; 15 + 16 + # TODO: Fill meta with appropriate information. 17 + }; 18 + }
+92
pkgs/misc/vscode-extensions/vscode-utils.nix
··· 1 + { stdenv, lib, fetchurl, runCommand, vscode, which }: 2 + 3 + let 4 + extendedPkgVersion = lib.getVersion vscode; 5 + extendedPkgName = lib.removeSuffix "-${extendedPkgVersion}" vscode.name; 6 + 7 + mktplcExtRefToFetchArgs = ext: { 8 + url = "https://${ext.publisher}.gallery.vsassets.io/_apis/public/gallery/publisher/${ext.publisher}/extension/${ext.name}/${ext.version}/assetbyname/Microsoft.VisualStudio.Services.VSIXPackage"; 9 + sha256 = ext.sha256; 10 + name = "${ext.name}.vsix"; 11 + }; 12 + 13 + buildVscodeExtension = a@{ 14 + name, 15 + namePrefix ? "${extendedPkgName}-extension-", 16 + src, 17 + configurePhase ? ":", 18 + buildPhase ? ":", 19 + dontPatchELF ? true, 20 + dontStrip ? true, 21 + buildInputs ? [], 22 + ... 23 + }: 24 + stdenv.mkDerivation (a // { 25 + 26 + name = namePrefix + name; 27 + 28 + inherit configurePhase buildPhase dontPatchELF dontStrip; 29 + 30 + # TODO: `which` is an encapsulation leak. It should have been hardwired 31 + # as part of the `code` wrapper. 32 + buildInputs = [ vscode which ] ++ buildInputs; 33 + 34 + unpackPhase = '' 35 + # TODO: Unfortunately, 'code' systematically creates its '.vscode' directory 36 + # even tough it has nothing to write in it. We need to redirect this 37 + # to a writeable location as the nix environment already has (but 38 + # to a non writeable one) otherwise the write will fail. 39 + # It would be preferrable if we could intercept / fix this at the source. 40 + HOME="$PWD/code_null_home" code \ 41 + --extensions-dir "$PWD" \ 42 + --install-extension "${toString src}" 43 + 44 + rm -Rf "$PWD/code_null_home" 45 + cd "$(find . -mindepth 1 -type d -print -quit)" 46 + ls -la 47 + ''; 48 + 49 + 50 + installPhase = '' 51 + mkdir -p "$out/share/${extendedPkgName}/extensions/${name}" 52 + find . -mindepth 1 -maxdepth 1 | xargs mv -t "$out/share/${extendedPkgName}/extensions/${name}/" 53 + ''; 54 + 55 + }); 56 + 57 + 58 + fetchVsixFromVscodeMarketplace = mktplcExtRef: 59 + fetchurl((mktplcExtRefToFetchArgs mktplcExtRef)); 60 + 61 + buildVscodeMarketplaceExtension = a@{ 62 + name ? "", 63 + src ? null, 64 + mktplcRef, 65 + ... 66 + }: assert "" == name; assert null == src; 67 + buildVscodeExtension ((removeAttrs a [ "mktplcRef" ]) // { 68 + name = "${mktplcRef.name}-${mktplcRef.version}"; 69 + src = fetchVsixFromVscodeMarketplace mktplcRef; 70 + }); 71 + 72 + mktplcRefAttrList = [ 73 + "name" 74 + "publisher" 75 + "version" 76 + "sha256" 77 + ]; 78 + 79 + mktplcExtRefToExtDrv = ext: 80 + buildVscodeMarketplaceExtension ((removeAttrs ext mktplcRefAttrList) // { 81 + mktplcRef = ext; 82 + }); 83 + 84 + extensionsFromVscodeMarketplace = mktplcExtRefList: 85 + builtins.map mktplcExtRefToExtDrv mktplcExtRefList; 86 + 87 + in 88 + 89 + { 90 + inherit fetchVsixFromVscodeMarketplace buildVscodeExtension 91 + buildVscodeMarketplaceExtension extensionsFromVscodeMarketplace; 92 + }
+6
pkgs/top-level/all-packages.nix
··· 16568 16568 16569 16569 vscode = callPackage ../applications/editors/vscode { }; 16570 16570 16571 + vscode-with-extensions = callPackage ../applications/editors/vscode-with-extensions {}; 16572 + 16573 + vscode-utils = callPackage ../misc/vscode-extensions/vscode-utils.nix {}; 16574 + 16575 + vscode-extensions = recurseIntoAttrs (callPackage ../misc/vscode-extensions {}); 16576 + 16571 16577 vue = callPackage ../applications/misc/vue { }; 16572 16578 16573 16579 vwm = callPackage ../applications/window-managers/vwm { };