summary refs log tree commit diff
path: root/pkgs/misc
diff options
context:
space:
mode:
authorRaymond Gauthier <jraygauthier@gmail.com>2017-08-23 21:24:57 -0400
committerRaymond Gauthier <jraygauthier@gmail.com>2017-08-23 21:31:57 -0400
commit763f7f75783a7c49140ccd703135bbbb244f1522 (patch)
tree842dfe0cf9ced6512409085956ab3294016dcf10 /pkgs/misc
parentd3532906dad30bfdd267748aae85b4dbb031151d (diff)
downloadnixlib-763f7f75783a7c49140ccd703135bbbb244f1522.tar
nixlib-763f7f75783a7c49140ccd703135bbbb244f1522.tar.gz
nixlib-763f7f75783a7c49140ccd703135bbbb244f1522.tar.bz2
nixlib-763f7f75783a7c49140ccd703135bbbb244f1522.tar.lz
nixlib-763f7f75783a7c49140ccd703135bbbb244f1522.tar.xz
nixlib-763f7f75783a7c49140ccd703135bbbb244f1522.tar.zst
nixlib-763f7f75783a7c49140ccd703135bbbb244f1522.zip
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.
Diffstat (limited to 'pkgs/misc')
-rw-r--r--pkgs/misc/vscode-extensions/default.nix17
-rw-r--r--pkgs/misc/vscode-extensions/vscode-utils.nix39
2 files changed, 26 insertions, 30 deletions
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 = [