vscode-with-extensions: define extensions.json

23b25e9d4d
This commit is contained in:
Edmund Wu 2022-12-06 20:41:22 -08:00 committed by Jonathan Ringer
parent 41de073c82
commit 66a6cd1d51
2 changed files with 49 additions and 6 deletions

View File

@ -5,6 +5,8 @@ let
src, src,
# Same as "Unique Identifier" on the extension's web page. # Same as "Unique Identifier" on the extension's web page.
# For the moment, only serve as unique extension dir. # For the moment, only serve as unique extension dir.
vscodeExtPublisher,
vscodeExtName,
vscodeExtUniqueId, vscodeExtUniqueId,
configurePhase ? '' configurePhase ? ''
runHook preConfigure runHook preConfigure
@ -23,7 +25,10 @@ let
name = "vscode-extension-${name}"; name = "vscode-extension-${name}";
inherit vscodeExtUniqueId; passthru = {
inherit vscodeExtPublisher vscodeExtName vscodeExtUniqueId;
};
inherit configurePhase buildPhase dontPatchELF dontStrip; inherit configurePhase buildPhase dontPatchELF dontStrip;
installPrefix = "share/vscode/extensions/${vscodeExtUniqueId}"; installPrefix = "share/vscode/extensions/${vscodeExtUniqueId}";
@ -54,9 +59,12 @@ let
}: assert "" == name; assert null == src; }: assert "" == name; assert null == src;
buildVscodeExtension ((removeAttrs a [ "mktplcRef" "vsix" ]) // { buildVscodeExtension ((removeAttrs a [ "mktplcRef" "vsix" ]) // {
name = "${mktplcRef.publisher}-${mktplcRef.name}-${mktplcRef.version}"; name = "${mktplcRef.publisher}-${mktplcRef.name}-${mktplcRef.version}";
version = mktplcRef.version;
src = if (vsix != null) src = if (vsix != null)
then vsix then vsix
else fetchVsixFromVscodeMarketplace mktplcRef; else fetchVsixFromVscodeMarketplace mktplcRef;
vscodeExtPublisher = mktplcRef.publisher;
vscodeExtName = mktplcRef.name;
vscodeExtUniqueId = "${mktplcRef.publisher}.${mktplcRef.name}"; vscodeExtUniqueId = "${mktplcRef.publisher}.${mktplcRef.name}";
}); });

View File

@ -1,4 +1,4 @@
{ lib, stdenv, runCommand, buildEnv, vscode, makeWrapper { lib, stdenv, runCommand, buildEnv, vscode, makeWrapper, writeText
, vscodeExtensions ? [] }: , vscodeExtensions ? [] }:
/* /*
@ -46,12 +46,47 @@ let
wrappedPkgVersion = lib.getVersion vscode; wrappedPkgVersion = lib.getVersion vscode;
wrappedPkgName = lib.removeSuffix "-${wrappedPkgVersion}" vscode.name; wrappedPkgName = lib.removeSuffix "-${wrappedPkgVersion}" vscode.name;
combinedExtensionsDrv = buildEnv { toExtensionJsonEntry = drv: rec {
name = "vscode-extensions"; identifier = {
paths = vscodeExtensions; id = "${drv.vscodeExtPublisher}.${drv.vscodeExtName}";
uuid = "";
};
version = drv.version;
location = {
"$mid" = 1;
fsPath = drv.outPath + "/share/vscode/extensions/${drv.vscodeExtUniqueId}";
path = location.fsPath;
scheme = "file";
};
metadata = {
id = identifier.uuid;
publisherId = "";
publisherDisplayName = drv.vscodeExtPublisher;
targetPlatform = "undefined";
isApplicationScoped = false;
updated = false;
isPreReleaseVersion = false;
installedTimestamp = 0;
preRelease = false;
};
}; };
extensionsFlag = lib.optionalString (vscodeExtensions != []) '' extensionJson = builtins.toJSON (map toExtensionJsonEntry vscodeExtensions);
extensionJsonFile = writeText "extensions.json" extensionJson;
extensionJsonOutput = runCommand "vscode-extensions-json" {} ''
mkdir -p $out/share/vscode/extensions
cp ${extensionJsonFile} $out/share/vscode/extensions/extensions.json
'';
combinedExtensionsDrv = buildEnv {
name = "vscode-extensions";
paths = vscodeExtensions ++ [ extensionJsonOutput ];
};
extensionsFlag = ''
--add-flags "--extensions-dir ${combinedExtensionsDrv}/share/vscode/extensions" --add-flags "--extensions-dir ${combinedExtensionsDrv}/share/vscode/extensions"
''; '';
in in