about summary refs log tree commit diff
path: root/pkgs/applications/editors/vscode/extensions/vscode-utils.nix
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/applications/editors/vscode/extensions/vscode-utils.nix')
-rw-r--r--pkgs/applications/editors/vscode/extensions/vscode-utils.nix211
1 files changed, 126 insertions, 85 deletions
diff --git a/pkgs/applications/editors/vscode/extensions/vscode-utils.nix b/pkgs/applications/editors/vscode/extensions/vscode-utils.nix
index 940a39a217624..d457b156aa97e 100644
--- a/pkgs/applications/editors/vscode/extensions/vscode-utils.nix
+++ b/pkgs/applications/editors/vscode/extensions/vscode-utils.nix
@@ -1,77 +1,101 @@
-{ stdenv, lib, buildEnv, writeShellScriptBin, fetchurl, vscode, unzip, jq }:
+{
+  stdenv,
+  lib,
+  buildEnv,
+  writeShellScriptBin,
+  fetchurl,
+  vscode,
+  unzip,
+  jq,
+}:
 let
-  buildVscodeExtension = a@{
-    name,
-    src,
-    # Same as "Unique Identifier" on the extension's web page.
-    # For the moment, only serve as unique extension dir.
-    vscodeExtPublisher,
-    vscodeExtName,
-    vscodeExtUniqueId,
-    configurePhase ? ''
-      runHook preConfigure
-      runHook postConfigure
-    '',
-    buildPhase ?''
-      runHook preBuild
-      runHook postBuild
-    '',
-    dontPatchELF ? true,
-    dontStrip ? true,
-    nativeBuildInputs ? [],
-    passthru ? { },
-    ...
-  }:
-  stdenv.mkDerivation ((removeAttrs a [ "vscodeExtUniqueId" ]) // {
-
-    name = "vscode-extension-${name}";
-
-    passthru = passthru // {
-      inherit vscodeExtPublisher vscodeExtName vscodeExtUniqueId;
-    };
-
-    inherit configurePhase buildPhase dontPatchELF dontStrip;
-
-    # Some .vsix files contain other directories (e.g., `package`) that we don't use.
-    # If other directories are present but `sourceRoot` is unset, the unpacker phase fails.
-    sourceRoot = "extension";
-
-    installPrefix = "share/vscode/extensions/${vscodeExtUniqueId}";
-
-    nativeBuildInputs = [ unzip ] ++ nativeBuildInputs;
-
-    installPhase = ''
-
-      runHook preInstall
-
-      mkdir -p "$out/$installPrefix"
-      find . -mindepth 1 -maxdepth 1 | xargs -d'\n' mv -t "$out/$installPrefix/"
-
-      runHook postInstall
-    '';
-
-  });
-
-  fetchVsixFromVscodeMarketplace = mktplcExtRef:
-    fetchurl (import ./mktplcExtRefToFetchArgs.nix mktplcExtRef);
-
-  buildVscodeMarketplaceExtension = a@{
-    name ? "",
-    src ? null,
-    vsix ? null,
-    mktplcRef,
-    ...
-  }: assert "" == name; assert null == src;
-  buildVscodeExtension ((removeAttrs a [ "mktplcRef" "vsix" ]) // {
-    name = "${mktplcRef.publisher}-${mktplcRef.name}-${mktplcRef.version}";
-    version = mktplcRef.version;
-    src = if (vsix != null)
-      then vsix
-      else fetchVsixFromVscodeMarketplace mktplcRef;
-    vscodeExtPublisher = mktplcRef.publisher;
-    vscodeExtName = mktplcRef.name;
-    vscodeExtUniqueId = "${mktplcRef.publisher}.${mktplcRef.name}";
-  });
+  buildVscodeExtension =
+    a@{
+      name,
+      src,
+      # Same as "Unique Identifier" on the extension's web page.
+      # For the moment, only serve as unique extension dir.
+      vscodeExtPublisher,
+      vscodeExtName,
+      vscodeExtUniqueId,
+      configurePhase ? ''
+        runHook preConfigure
+        runHook postConfigure
+      '',
+      buildPhase ? ''
+        runHook preBuild
+        runHook postBuild
+      '',
+      dontPatchELF ? true,
+      dontStrip ? true,
+      nativeBuildInputs ? [ ],
+      passthru ? { },
+      ...
+    }:
+    stdenv.mkDerivation (
+      (removeAttrs a [ "vscodeExtUniqueId" ])
+      // {
+
+        name = "vscode-extension-${name}";
+
+        passthru = passthru // {
+          inherit vscodeExtPublisher vscodeExtName vscodeExtUniqueId;
+        };
+
+        inherit
+          configurePhase
+          buildPhase
+          dontPatchELF
+          dontStrip
+          ;
+
+        # Some .vsix files contain other directories (e.g., `package`) that we don't use.
+        # If other directories are present but `sourceRoot` is unset, the unpacker phase fails.
+        sourceRoot = "extension";
+
+        installPrefix = "share/vscode/extensions/${vscodeExtUniqueId}";
+
+        nativeBuildInputs = [ unzip ] ++ nativeBuildInputs;
+
+        installPhase = ''
+
+          runHook preInstall
+
+          mkdir -p "$out/$installPrefix"
+          find . -mindepth 1 -maxdepth 1 | xargs -d'\n' mv -t "$out/$installPrefix/"
+
+          runHook postInstall
+        '';
+      }
+    );
+
+  fetchVsixFromVscodeMarketplace =
+    mktplcExtRef: fetchurl (import ./mktplcExtRefToFetchArgs.nix mktplcExtRef);
+
+  buildVscodeMarketplaceExtension =
+    a@{
+      name ? "",
+      src ? null,
+      vsix ? null,
+      mktplcRef,
+      ...
+    }:
+    assert "" == name;
+    assert null == src;
+    buildVscodeExtension (
+      (removeAttrs a [
+        "mktplcRef"
+        "vsix"
+      ])
+      // {
+        name = "${mktplcRef.publisher}-${mktplcRef.name}-${mktplcRef.version}";
+        version = mktplcRef.version;
+        src = if (vsix != null) then vsix else fetchVsixFromVscodeMarketplace mktplcRef;
+        vscodeExtPublisher = mktplcRef.publisher;
+        vscodeExtName = mktplcRef.name;
+        vscodeExtUniqueId = "${mktplcRef.publisher}.${mktplcRef.name}";
+      }
+    );
 
   mktplcRefAttrList = [
     "name"
@@ -82,14 +106,18 @@ let
     "arch"
   ];
 
-  mktplcExtRefToExtDrv = ext:
-    buildVscodeMarketplaceExtension (removeAttrs ext mktplcRefAttrList // {
-      mktplcRef = builtins.intersectAttrs (lib.genAttrs mktplcRefAttrList (_: null)) ext;
-    });
+  mktplcExtRefToExtDrv =
+    ext:
+    buildVscodeMarketplaceExtension (
+      removeAttrs ext mktplcRefAttrList
+      // {
+        mktplcRef = builtins.intersectAttrs (lib.genAttrs mktplcRefAttrList (_: null)) ext;
+      }
+    );
 
   extensionFromVscodeMarketplace = mktplcExtRefToExtDrv;
-  extensionsFromVscodeMarketplace = mktplcExtRefList:
-    builtins.map extensionFromVscodeMarketplace mktplcExtRefList;
+  extensionsFromVscodeMarketplace =
+    mktplcExtRefList: builtins.map extensionFromVscodeMarketplace mktplcExtRefList;
 
   vscodeWithConfiguration = import ./vscodeWithConfiguration.nix {
     inherit lib extensionsFromVscodeMarketplace writeShellScriptBin;
@@ -102,7 +130,13 @@ let
   };
 
   vscodeEnv = import ./vscodeEnv.nix {
-    inherit lib buildEnv writeShellScriptBin extensionsFromVscodeMarketplace jq;
+    inherit
+      lib
+      buildEnv
+      writeShellScriptBin
+      extensionsFromVscodeMarketplace
+      jq
+      ;
     vscodeDefault = vscode;
   };
 
@@ -139,9 +173,16 @@ let
   toExtensionJson = extensions: builtins.toJSON (map toExtensionJsonEntry extensions);
 in
 {
-  inherit fetchVsixFromVscodeMarketplace buildVscodeExtension
-          buildVscodeMarketplaceExtension extensionFromVscodeMarketplace
-          extensionsFromVscodeMarketplace
-          vscodeWithConfiguration vscodeExts2nix vscodeEnv
-          toExtensionJsonEntry toExtensionJson;
+  inherit
+    fetchVsixFromVscodeMarketplace
+    buildVscodeExtension
+    buildVscodeMarketplaceExtension
+    extensionFromVscodeMarketplace
+    extensionsFromVscodeMarketplace
+    vscodeWithConfiguration
+    vscodeExts2nix
+    vscodeEnv
+    toExtensionJsonEntry
+    toExtensionJson
+    ;
 }