vscode-with-extension: improvements

-  Now simply let the default `unpackPhase` unzip the vsix file. This
    should allow users to retrieve the extension directly from github.
 -  Extensions now installed using their unique id as install folder.
 -  Extensions under `vscode-extensions` now use the unique id
    as extension name.
This commit is contained in:
Raymond Gauthier 2017-08-23 21:24:57 -04:00
parent d3532906da
commit 763f7f7578
3 changed files with 30 additions and 34 deletions

View File

@ -2,7 +2,7 @@
, vscodeExtensions ? [] }:
/*
`vsixExtensions`
`vscodeExtensions`
: A set of vscode extensions to be installed alongside the editor. Here's a an
example:
@ -10,12 +10,12 @@
vscode-with-extensions.override {
# When the extension is already available in the default extensions set.
vscodeExtensions = with vscodeExtensions; [
nix
vscodeExtensions = with vscode-extensions; [
bbenoist.Nix
]
# Concise version from the vscode market place when not available in the default set.
++ vscodeUtils.extensionsFromVscodeMarketplace [
++ vscode-utils.extensionsFromVscodeMarketplace [
{
name = "code-runner";
publisher = "formulahendry";

View File

@ -3,16 +3,23 @@
let
inherit (vscode-utils) buildVscodeExtension buildVscodeMarketplaceExtension;
in
#
# Unless there is a good reason not to, we attemp to use the same name as the
# extension's unique identifier (the name the extension gets when installed
# from vscode under `~/.vscode`) and found on the marketplace extension page.
# So an extension's attribute name should be of the form:
# "${mktplcRef.publisher}.${mktplcRef.name}".
#
rec {
nix = buildVscodeMarketplaceExtension {
bbenoist.Nix = buildVscodeMarketplaceExtension {
mktplcRef = {
name = "nix";
name = "Nix";
publisher = "bbenoist";
version = "1.0.1";
sha256 = "0zd0n9f5z1f0ckzfjr38xw2zzmcxg1gjrava7yahg5cvdcw6l35b";
};
# TODO: Fill meta with appropriate information.
meta = with stdenv.lib; {
license = licenses.mit;
};
};
}

View File

@ -1,4 +1,4 @@
{ stdenv, lib, fetchurl, runCommand, vscode, which }:
{ stdenv, lib, fetchurl, runCommand, vscode, unzip }:
let
extendedPkgVersion = lib.getVersion vscode;
@ -7,13 +7,18 @@ let
mktplcExtRefToFetchArgs = ext: {
url = "https://${ext.publisher}.gallery.vsassets.io/_apis/public/gallery/publisher/${ext.publisher}/extension/${ext.name}/${ext.version}/assetbyname/Microsoft.VisualStudio.Services.VSIXPackage";
sha256 = ext.sha256;
name = "${ext.name}.vsix";
# The `*.vsix` file is in the end a simple zip file. Change the extension
# so that existing `unzip` hooks takes care of the unpacking.
name = "${ext.publisher}-${ext.name}.zip";
};
buildVscodeExtension = a@{
name,
namePrefix ? "${extendedPkgName}-extension-",
src,
# Same as "Unique Identifier" on the extension's web page.
# For the moment, only serve as unique extension dir.
vscodeExtUniqueId,
configurePhase ? ":",
buildPhase ? ":",
dontPatchELF ? true,
@ -21,35 +26,18 @@ let
buildInputs ? [],
...
}:
stdenv.mkDerivation (a // {
stdenv.mkDerivation ((removeAttrs a [ "vscodeExtUniqueId" ]) // {
name = namePrefix + name;
inherit vscodeExtUniqueId;
inherit configurePhase buildPhase dontPatchELF dontStrip;
# TODO: `which` is an encapsulation leak. It should have been hardwired
# as part of the `code` wrapper.
buildInputs = [ vscode which ] ++ buildInputs;
unpackPhase = ''
# TODO: Unfortunately, 'code' systematically creates its '.vscode' directory
# even tough it has nothing to write in it. We need to redirect this
# to a writeable location as the nix environment already has (but
# to a non writeable one) otherwise the write will fail.
# It would be preferrable if we could intercept / fix this at the source.
HOME="$PWD/code_null_home" code \
--extensions-dir "$PWD" \
--install-extension "${toString src}"
rm -Rf "$PWD/code_null_home"
cd "$(find . -mindepth 1 -type d -print -quit)"
ls -la
'';
buildInputs = [ unzip ] ++ buildInputs;
installPhase = ''
mkdir -p "$out/share/${extendedPkgName}/extensions/${name}"
find . -mindepth 1 -maxdepth 1 | xargs mv -t "$out/share/${extendedPkgName}/extensions/${name}/"
mkdir -p "$out/share/${extendedPkgName}/extensions/${vscodeExtUniqueId}"
find . -mindepth 1 -maxdepth 1 | xargs mv -t "$out/share/${extendedPkgName}/extensions/${vscodeExtUniqueId}/"
'';
});
@ -65,8 +53,9 @@ let
...
}: assert "" == name; assert null == src;
buildVscodeExtension ((removeAttrs a [ "mktplcRef" ]) // {
name = "${mktplcRef.name}-${mktplcRef.version}";
name = "${mktplcRef.publisher}-${mktplcRef.name}-${mktplcRef.version}";
src = fetchVsixFromVscodeMarketplace mktplcRef;
vscodeExtUniqueId = "${mktplcRef.publisher}.${mktplcRef.name}";
});
mktplcRefAttrList = [