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,
# 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
@ -23,7 +25,10 @@ let
name = "vscode-extension-${name}";
inherit vscodeExtUniqueId;
passthru = {
inherit vscodeExtPublisher vscodeExtName vscodeExtUniqueId;
};
inherit configurePhase buildPhase dontPatchELF dontStrip;
installPrefix = "share/vscode/extensions/${vscodeExtUniqueId}";
@ -54,9 +59,12 @@ let
}: 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}";
});

View File

@ -1,4 +1,4 @@
{ lib, stdenv, runCommand, buildEnv, vscode, makeWrapper
{ lib, stdenv, runCommand, buildEnv, vscode, makeWrapper, writeText
, vscodeExtensions ? [] }:
/*
@ -46,12 +46,47 @@ let
wrappedPkgVersion = lib.getVersion vscode;
wrappedPkgName = lib.removeSuffix "-${wrappedPkgVersion}" vscode.name;
combinedExtensionsDrv = buildEnv {
name = "vscode-extensions";
paths = vscodeExtensions;
toExtensionJsonEntry = drv: rec {
identifier = {
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"
'';
in