Unverified Commit b98a9275 authored by Philip Taron's avatar Philip Taron Committed by GitHub
Browse files

buildVscodeExtension: support `finalAttrs` through `lib.extendMkDerivation` (#390180)

parents 481660ff 7e022a68
Loading
Loading
Loading
Loading
+53 −53
Original line number Diff line number Diff line
@@ -9,10 +9,15 @@
  jq,
}:
let
  buildVscodeExtension =
    a@{
  buildVscodeExtension = lib.extendMkDerivation {
    constructDrv = stdenv.mkDerivation;
    excludeDrvArgNames = [
      "vscodeExtUniqueId"
    ];
    extendDrvArgs =
      finalAttrs:
      {
        pname ? null, # Only optional for backward compatibility.
      src,
        # Same as "Unique Identifier" on the extension's web page.
        # For the moment, only serve as unique extension dir.
        vscodeExtPublisher,
@@ -32,15 +37,8 @@ let
        passthru ? { },
        ...
      }:
    stdenv.mkDerivation (
      (removeAttrs a [
        "vscodeExtUniqueId"
        "pname"
      ])
      // (lib.optionalAttrs (pname != null) {
      {
        pname = "vscode-extension-${pname}";
      })
      // {

        passthru = passthru // {
          inherit vscodeExtPublisher vscodeExtName vscodeExtUniqueId;
@@ -57,12 +55,12 @@ let
        # If other directories are present but `sourceRoot` is unset, the unpacker phase fails.
        sourceRoot = "extension";

        # This cannot be removed, it is used by some extensions.
        installPrefix = "share/vscode/extensions/${vscodeExtUniqueId}";

        nativeBuildInputs = [ unzip ] ++ nativeBuildInputs;

        installPhase = ''

          runHook preInstall

          mkdir -p "$out/$installPrefix"
@@ -70,14 +68,21 @@ let

          runHook postInstall
        '';
      }
    );
      };
  };

  fetchVsixFromVscodeMarketplace =
    mktplcExtRef: fetchurl (import ./mktplcExtRefToFetchArgs.nix mktplcExtRef);

  buildVscodeMarketplaceExtension =
    a@{
  buildVscodeMarketplaceExtension = lib.extendMkDerivation {
    constructDrv = buildVscodeExtension;
    excludeDrvArgNames = [
      "mktplcRef"
      "vsix"
    ];
    extendDrvArgs =
      finalAttrs:
      {
        name ? "",
        src ? null,
        vsix ? null,
@@ -86,20 +91,15 @@ let
      }:
      assert "" == name;
      assert null == src;
    buildVscodeExtension (
      (removeAttrs a [
        "mktplcRef"
        "vsix"
      ])
      // {
      {
        inherit (mktplcRef) version;
        pname = "${mktplcRef.publisher}-${mktplcRef.name}";
        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"