nixpkgs/pkgs/applications/editors/vscode/extensions/vscode-utils.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

148 lines
4.0 KiB
Nix
Raw Normal View History

2020-02-02 03:26:35 +00:00
{ stdenv, lib, buildEnv, writeShellScriptBin, fetchurl, vscode, unzip, jq }:
2017-08-12 04:27:17 +00:00
let
buildVscodeExtension = a@{
name,
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
'',
2017-08-12 04:27:17 +00:00
dontPatchELF ? true,
dontStrip ? true,
nativeBuildInputs ? [],
2023-01-22 09:46:19 +00:00
passthru ? { },
2017-08-12 04:27:17 +00:00
...
}:
2020-05-30 02:21:04 +00:00
stdenv.mkDerivation ((removeAttrs a [ "vscodeExtUniqueId" ]) // {
2017-08-12 04:27:17 +00:00
name = "vscode-extension-${name}";
2017-08-12 04:27:17 +00:00
2023-01-22 09:46:19 +00:00
passthru = passthru // {
inherit vscodeExtPublisher vscodeExtName vscodeExtUniqueId;
};
2017-08-12 04:27:17 +00:00
inherit configurePhase buildPhase dontPatchELF dontStrip;
# Some .vsix files contain other directories (e.g., `package`) that we don't use.
# If other directories are present but `sourceRoot` is unset, the unpacker phase fails.
sourceRoot = "extension";
installPrefix = "share/vscode/extensions/${vscodeExtUniqueId}";
nativeBuildInputs = [ unzip ] ++ nativeBuildInputs;
2017-08-12 04:27:17 +00:00
installPhase = ''
runHook preInstall
mkdir -p "$out/$installPrefix"
find . -mindepth 1 -maxdepth 1 | xargs -d'\n' mv -t "$out/$installPrefix/"
runHook postInstall
2017-08-12 04:27:17 +00:00
'';
});
fetchVsixFromVscodeMarketplace = mktplcExtRef:
fetchurl (import ./mktplcExtRefToFetchArgs.nix mktplcExtRef);
2017-08-12 04:27:17 +00:00
buildVscodeMarketplaceExtension = a@{
name ? "",
src ? null,
2020-03-28 02:04:59 +00:00
vsix ? null,
2017-08-12 04:27:17 +00:00
mktplcRef,
...
}: assert "" == name; assert null == src;
2020-03-28 02:04:59 +00:00
buildVscodeExtension ((removeAttrs a [ "mktplcRef" "vsix" ]) // {
name = "${mktplcRef.publisher}-${mktplcRef.name}-${mktplcRef.version}";
version = mktplcRef.version;
2020-03-28 02:04:59 +00:00
src = if (vsix != null)
then vsix
else fetchVsixFromVscodeMarketplace mktplcRef;
vscodeExtPublisher = mktplcRef.publisher;
vscodeExtName = mktplcRef.name;
vscodeExtUniqueId = "${mktplcRef.publisher}.${mktplcRef.name}";
2017-08-12 04:27:17 +00:00
});
mktplcRefAttrList = [
"name"
"publisher"
"version"
"sha256"
"hash"
"arch"
2017-08-12 04:27:17 +00:00
];
mktplcExtRefToExtDrv = ext:
buildVscodeMarketplaceExtension (removeAttrs ext mktplcRefAttrList // {
mktplcRef = builtins.intersectAttrs (lib.genAttrs mktplcRefAttrList (_: null)) ext;
});
2017-08-12 04:27:17 +00:00
extensionFromVscodeMarketplace = mktplcExtRefToExtDrv;
2017-08-12 04:27:17 +00:00
extensionsFromVscodeMarketplace = mktplcExtRefList:
builtins.map extensionFromVscodeMarketplace mktplcExtRefList;
2017-08-12 04:27:17 +00:00
vscodeWithConfiguration = import ./vscodeWithConfiguration.nix {
inherit lib extensionsFromVscodeMarketplace writeShellScriptBin;
vscodeDefault = vscode;
};
vscodeExts2nix = import ./vscodeExts2nix.nix {
inherit lib writeShellScriptBin;
vscodeDefault = vscode;
};
vscodeEnv = import ./vscodeEnv.nix {
2020-02-02 03:26:35 +00:00
inherit lib buildEnv writeShellScriptBin extensionsFromVscodeMarketplace jq;
vscodeDefault = vscode;
};
2023-01-12 14:07:36 +00:00
toExtensionJsonEntry = ext: rec {
identifier = {
id = ext.vscodeExtUniqueId;
uuid = "";
};
version = ext.version;
relativeLocation = ext.vscodeExtUniqueId;
2023-01-12 14:07:36 +00:00
location = {
"$mid" = 1;
fsPath = ext.outPath + "/share/vscode/extensions/${ext.vscodeExtUniqueId}";
path = location.fsPath;
scheme = "file";
};
metadata = {
id = "";
publisherId = "";
publisherDisplayName = ext.vscodeExtPublisher;
targetPlatform = "undefined";
isApplicationScoped = false;
updated = false;
isPreReleaseVersion = false;
installedTimestamp = 0;
preRelease = false;
};
};
toExtensionJson = extensions: builtins.toJSON (map toExtensionJsonEntry extensions);
2020-05-30 02:21:04 +00:00
in
2017-08-12 04:27:17 +00:00
{
inherit fetchVsixFromVscodeMarketplace buildVscodeExtension
buildVscodeMarketplaceExtension extensionFromVscodeMarketplace
extensionsFromVscodeMarketplace
2023-01-12 14:07:36 +00:00
vscodeWithConfiguration vscodeExts2nix vscodeEnv
toExtensionJsonEntry toExtensionJson;
}