From f0f9bdd5774e1f163d1d6f8d9aa7ecb90332ccac Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Sat, 15 Mar 2025 17:41:33 +0100 Subject: [PATCH 1/3] buildVscodeExtension: support `finalAttrs` through `lib.extendMkDerivation` --- .../vscode/extensions/vscode-utils.nix | 67 +++++++++---------- 1 file changed, 33 insertions(+), 34 deletions(-) diff --git a/pkgs/applications/editors/vscode/extensions/vscode-utils.nix b/pkgs/applications/editors/vscode/extensions/vscode-utils.nix index 74d674dced92b..6d6b1d294fa17 100644 --- a/pkgs/applications/editors/vscode/extensions/vscode-utils.nix +++ b/pkgs/applications/editors/vscode/extensions/vscode-utils.nix @@ -9,38 +9,37 @@ jq, }: let - buildVscodeExtension = - a@{ - 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, - vscodeExtName, - vscodeExtUniqueId, - configurePhase ? '' - runHook preConfigure - runHook postConfigure - '', - buildPhase ? '' - runHook preBuild - runHook postBuild - '', - dontPatchELF ? true, - dontStrip ? true, - nativeBuildInputs ? [ ], - passthru ? { }, - ... - }: - stdenv.mkDerivation ( - (removeAttrs a [ - "vscodeExtUniqueId" - "pname" - ]) - // (lib.optionalAttrs (pname != null) { + 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, + vscodeExtName, + vscodeExtUniqueId, + configurePhase ? '' + runHook preConfigure + runHook postConfigure + '', + buildPhase ? '' + runHook preBuild + runHook postBuild + '', + dontPatchELF ? true, + dontStrip ? true, + nativeBuildInputs ? [ ], + passthru ? { }, + ... + }: + { pname = "vscode-extension-${pname}"; - }) - // { passthru = passthru // { inherit vscodeExtPublisher vscodeExtName vscodeExtUniqueId; @@ -57,12 +56,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,8 +69,8 @@ let runHook postInstall ''; - } - ); + }; + }; fetchVsixFromVscodeMarketplace = mktplcExtRef: fetchurl (import ./mktplcExtRefToFetchArgs.nix mktplcExtRef); From 82d30e0d4fb1275fc148498eaafe42bc04966733 Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Sat, 15 Mar 2025 18:02:51 +0100 Subject: [PATCH 2/3] buildVscodeMarketplaceExtension: support `finalAttrs` through `lib.extendMkDerivation` --- .../vscode/extensions/vscode-utils.nix | 40 ++++++++++--------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/pkgs/applications/editors/vscode/extensions/vscode-utils.nix b/pkgs/applications/editors/vscode/extensions/vscode-utils.nix index 6d6b1d294fa17..ad1abe7f94020 100644 --- a/pkgs/applications/editors/vscode/extensions/vscode-utils.nix +++ b/pkgs/applications/editors/vscode/extensions/vscode-utils.nix @@ -75,30 +75,32 @@ let 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" - ]) - // { + buildVscodeMarketplaceExtension = lib.extendMkDerivation { + constructDrv = buildVscodeExtension; + excludeDrvArgNames = [ + "mktplcRef" + "vsix" + ]; + extendDrvArgs = + finalAttrs: + { + name ? "", + src ? null, + vsix ? null, + mktplcRef, + ... + }: + assert "" == name; + assert null == src; + { + 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" From 7e022a68d457d9ece55c65b0b755c9e0eec491c6 Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Sat, 15 Mar 2025 18:55:19 +0100 Subject: [PATCH 3/3] buildVscodeExtension: remove unused parameter `src` --- pkgs/applications/editors/vscode/extensions/vscode-utils.nix | 1 - 1 file changed, 1 deletion(-) diff --git a/pkgs/applications/editors/vscode/extensions/vscode-utils.nix b/pkgs/applications/editors/vscode/extensions/vscode-utils.nix index ad1abe7f94020..acea5cb1a2291 100644 --- a/pkgs/applications/editors/vscode/extensions/vscode-utils.nix +++ b/pkgs/applications/editors/vscode/extensions/vscode-utils.nix @@ -18,7 +18,6 @@ let 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,