Merge pull request #28526 from jraygauthier/jrg/vscode-extensions-improvs

vscode-with-extension: improvements

authored by Jörg Thalheim and committed by GitHub ab3de8ed 733151b7

+30 -34
+4 -4
pkgs/applications/editors/vscode-with-extensions/default.nix
··· 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 ··· 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";
··· 2 , vscodeExtensions ? [] }: 3 4 /* 5 + `vscodeExtensions` 6 : A set of vscode extensions to be installed alongside the editor. Here's a an 7 example: 8 ··· 10 vscode-with-extensions.override { 11 12 # When the extension is already available in the default extensions set. 13 + vscodeExtensions = with vscode-extensions; [ 14 + bbenoist.Nix 15 ] 16 17 # Concise version from the vscode market place when not available in the default set. 18 + ++ vscode-utils.extensionsFromVscodeMarketplace [ 19 { 20 name = "code-runner"; 21 publisher = "formulahendry";
+12 -5
pkgs/misc/vscode-extensions/default.nix
··· 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 }
··· 3 let 4 inherit (vscode-utils) buildVscodeExtension buildVscodeMarketplaceExtension; 5 in 6 + # 7 + # Unless there is a good reason not to, we attemp to use the same name as the 8 + # extension's unique identifier (the name the extension gets when installed 9 + # from vscode under `~/.vscode`) and found on the marketplace extension page. 10 + # So an extension's attribute name should be of the form: 11 + # "${mktplcRef.publisher}.${mktplcRef.name}". 12 + # 13 rec { 14 + bbenoist.Nix = buildVscodeMarketplaceExtension { 15 mktplcRef = { 16 + name = "Nix"; 17 publisher = "bbenoist"; 18 version = "1.0.1"; 19 sha256 = "0zd0n9f5z1f0ckzfjr38xw2zzmcxg1gjrava7yahg5cvdcw6l35b"; 20 }; 21 + meta = with stdenv.lib; { 22 + license = licenses.mit; 23 + }; 24 }; 25 }
+14 -25
pkgs/misc/vscode-extensions/vscode-utils.nix
··· 1 - { stdenv, lib, fetchurl, runCommand, vscode, which }: 2 3 let 4 extendedPkgVersion = lib.getVersion vscode; ··· 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, ··· 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 }); ··· 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 = [
··· 1 + { stdenv, lib, fetchurl, runCommand, vscode, unzip }: 2 3 let 4 extendedPkgVersion = lib.getVersion vscode; ··· 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 + # The `*.vsix` file is in the end a simple zip file. Change the extension 11 + # so that existing `unzip` hooks takes care of the unpacking. 12 + name = "${ext.publisher}-${ext.name}.zip"; 13 }; 14 15 buildVscodeExtension = a@{ 16 name, 17 namePrefix ? "${extendedPkgName}-extension-", 18 src, 19 + # Same as "Unique Identifier" on the extension's web page. 20 + # For the moment, only serve as unique extension dir. 21 + vscodeExtUniqueId, 22 configurePhase ? ":", 23 buildPhase ? ":", 24 dontPatchELF ? true, ··· 26 buildInputs ? [], 27 ... 28 }: 29 + stdenv.mkDerivation ((removeAttrs a [ "vscodeExtUniqueId" ]) // { 30 31 name = namePrefix + name; 32 33 + inherit vscodeExtUniqueId; 34 inherit configurePhase buildPhase dontPatchELF dontStrip; 35 36 + buildInputs = [ unzip ] ++ buildInputs; 37 38 installPhase = '' 39 + mkdir -p "$out/share/${extendedPkgName}/extensions/${vscodeExtUniqueId}" 40 + find . -mindepth 1 -maxdepth 1 | xargs mv -t "$out/share/${extendedPkgName}/extensions/${vscodeExtUniqueId}/" 41 ''; 42 43 }); ··· 53 ... 54 }: assert "" == name; assert null == src; 55 buildVscodeExtension ((removeAttrs a [ "mktplcRef" ]) // { 56 + name = "${mktplcRef.publisher}-${mktplcRef.name}-${mktplcRef.version}"; 57 src = fetchVsixFromVscodeMarketplace mktplcRef; 58 + vscodeExtUniqueId = "${mktplcRef.publisher}.${mktplcRef.name}"; 59 }); 60 61 mktplcRefAttrList = [