From e47edd6f18752c5072e6bd8278cc125d75bb1f84 Mon Sep 17 00:00:00 2001 From: jopejoe1 Date: Sat, 9 Nov 2024 11:22:40 +0100 Subject: [PATCH 1/5] vscode-extensions: set pname (cherry picked from commit 7b47ad2dfd84863fb3a8d4f83e8b93ddd892fa16) --- .../extensions/rust-lang.rust-analyzer/default.nix | 3 +-- .../editors/vscode/extensions/vscode-utils.nix | 11 +++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/pkgs/applications/editors/vscode/extensions/rust-lang.rust-analyzer/default.nix b/pkgs/applications/editors/vscode/extensions/rust-lang.rust-analyzer/default.nix index e937da9c44b32..bcb076135ae14 100644 --- a/pkgs/applications/editors/vscode/extensions/rust-lang.rust-analyzer/default.nix +++ b/pkgs/applications/editors/vscode/extensions/rust-lang.rust-analyzer/default.nix @@ -72,8 +72,7 @@ let }; in vscode-utils.buildVscodeExtension { - inherit version vsix; - name = "${pname}-${version}"; + inherit version vsix pname; src = "${vsix}/${pname}.zip"; vscodeExtUniqueId = "${publisher}.${pname}"; vscodeExtPublisher = publisher; diff --git a/pkgs/applications/editors/vscode/extensions/vscode-utils.nix b/pkgs/applications/editors/vscode/extensions/vscode-utils.nix index d457b156aa97e..bd0390eaa84b0 100644 --- a/pkgs/applications/editors/vscode/extensions/vscode-utils.nix +++ b/pkgs/applications/editors/vscode/extensions/vscode-utils.nix @@ -11,7 +11,7 @@ let buildVscodeExtension = a@{ - name, + pname, src, # Same as "Unique Identifier" on the extension's web page. # For the moment, only serve as unique extension dir. @@ -33,10 +33,13 @@ let ... }: stdenv.mkDerivation ( - (removeAttrs a [ "vscodeExtUniqueId" ]) + (removeAttrs a [ + "vscodeExtUniqueId" + "pname" + ]) // { - name = "vscode-extension-${name}"; + pname = "vscode-extension-${pname}"; passthru = passthru // { inherit vscodeExtPublisher vscodeExtName vscodeExtUniqueId; @@ -88,7 +91,7 @@ let "vsix" ]) // { - name = "${mktplcRef.publisher}-${mktplcRef.name}-${mktplcRef.version}"; + pname = "${mktplcRef.publisher}-${mktplcRef.name}"; version = mktplcRef.version; src = if (vsix != null) then vsix else fetchVsixFromVscodeMarketplace mktplcRef; vscodeExtPublisher = mktplcRef.publisher; From 6db5a533dff331c201e81a9a8504e960acf50f86 Mon Sep 17 00:00:00 2001 From: Bryan Lai Date: Mon, 2 Dec 2024 18:45:25 +0800 Subject: [PATCH 2/5] vscode-extensions: make `pname` optional Many code in the wild still use `vscode-utils.buildVscodeExtension` with the `name` argument, so it would be better to make it optional. For example, a github code search of `buildVscodeExtension` returns 100+ results, most of them uses the `name` argument: https://github.com/search?q=buildVscodeExtension+language%3ANix&type=code&l=Nix (cherry picked from commit 09801c985b4449de0736603b1c2d8652bfab4b93) --- .../editors/vscode/extensions/vscode-utils.nix | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pkgs/applications/editors/vscode/extensions/vscode-utils.nix b/pkgs/applications/editors/vscode/extensions/vscode-utils.nix index bd0390eaa84b0..74d674dced92b 100644 --- a/pkgs/applications/editors/vscode/extensions/vscode-utils.nix +++ b/pkgs/applications/editors/vscode/extensions/vscode-utils.nix @@ -11,7 +11,7 @@ let buildVscodeExtension = a@{ - pname, + 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. @@ -37,9 +37,10 @@ let "vscodeExtUniqueId" "pname" ]) - // { - + // (lib.optionalAttrs (pname != null) { pname = "vscode-extension-${pname}"; + }) + // { passthru = passthru // { inherit vscodeExtPublisher vscodeExtName vscodeExtUniqueId; From e5c744c68feb31c5927f58b49e6b20ad8eb8ab02 Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Sat, 15 Mar 2025 17:41:33 +0100 Subject: [PATCH 3/5] buildVscodeExtension: support `finalAttrs` through `lib.extendMkDerivation` (cherry picked from commit f0f9bdd5774e1f163d1d6f8d9aa7ecb90332ccac) --- .../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 84e251ad511e96e57a59996040268583a7424420 Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Sat, 15 Mar 2025 18:02:51 +0100 Subject: [PATCH 4/5] buildVscodeMarketplaceExtension: support `finalAttrs` through `lib.extendMkDerivation` (cherry picked from commit 82d30e0d4fb1275fc148498eaafe42bc04966733) --- .../vscode/extensions/vscode-utils.nix | 38 ++++++++++--------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/pkgs/applications/editors/vscode/extensions/vscode-utils.nix b/pkgs/applications/editors/vscode/extensions/vscode-utils.nix index 6d6b1d294fa17..7dd34ce384162 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; + { 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 0ba0e054478dbf6b3d439bfab07db3c119f4e04a Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Sat, 15 Mar 2025 18:55:19 +0100 Subject: [PATCH 5/5] buildVscodeExtension: remove unused parameter `src` (cherry picked from commit 7e022a68d457d9ece55c65b0b755c9e0eec491c6) --- 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 7dd34ce384162..ddf705e27e9cd 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,