From 763f7f75783a7c49140ccd703135bbbb244f1522 Mon Sep 17 00:00:00 2001 From: Raymond Gauthier Date: Wed, 23 Aug 2017 21:24:57 -0400 Subject: [PATCH] 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. --- .../vscode-with-extensions/default.nix | 8 ++-- pkgs/misc/vscode-extensions/default.nix | 17 +++++--- pkgs/misc/vscode-extensions/vscode-utils.nix | 39 +++++++------------ 3 files changed, 30 insertions(+), 34 deletions(-) diff --git a/pkgs/applications/editors/vscode-with-extensions/default.nix b/pkgs/applications/editors/vscode-with-extensions/default.nix index 983acbbac197..c54c8a4277f1 100644 --- a/pkgs/applications/editors/vscode-with-extensions/default.nix +++ b/pkgs/applications/editors/vscode-with-extensions/default.nix @@ -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"; diff --git a/pkgs/misc/vscode-extensions/default.nix b/pkgs/misc/vscode-extensions/default.nix index 12900907c00c..d357c43abd85 100644 --- a/pkgs/misc/vscode-extensions/default.nix +++ b/pkgs/misc/vscode-extensions/default.nix @@ -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; + }; }; } \ No newline at end of file diff --git a/pkgs/misc/vscode-extensions/vscode-utils.nix b/pkgs/misc/vscode-extensions/vscode-utils.nix index 759449a745b0..f6e906ab575b 100644 --- a/pkgs/misc/vscode-extensions/vscode-utils.nix +++ b/pkgs/misc/vscode-extensions/vscode-utils.nix @@ -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 = [