nixpkgs/pkgs/misc/vscode-extensions/vscode-utils.nix

101 lines
2.7 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.
vscodeExtUniqueId,
configurePhase ? ''
runHook preConfigure
runHook postConfigure
'',
buildPhase ?''
runHook preBuild
runHook postBuild
'',
2017-08-12 04:27:17 +00:00
dontPatchELF ? true,
dontStrip ? true,
nativeBuildInputs ? [],
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
inherit vscodeExtUniqueId;
2017-08-12 04:27:17 +00:00
inherit configurePhase buildPhase dontPatchELF dontStrip;
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}";
2020-03-28 02:04:59 +00:00
src = if (vsix != null)
then vsix
else fetchVsixFromVscodeMarketplace mktplcRef;
vscodeExtUniqueId = "${mktplcRef.publisher}.${mktplcRef.name}";
2017-08-12 04:27:17 +00:00
});
mktplcRefAttrList = [
"name"
"publisher"
"version"
"sha256"
];
mktplcExtRefToExtDrv = ext:
buildVscodeMarketplaceExtension ((removeAttrs ext mktplcRefAttrList) // {
mktplcRef = 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;
};
2020-05-30 02:21:04 +00:00
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;
};
2020-05-30 02:21:04 +00:00
in
2017-08-12 04:27:17 +00:00
{
inherit fetchVsixFromVscodeMarketplace buildVscodeExtension
buildVscodeMarketplaceExtension extensionFromVscodeMarketplace
extensionsFromVscodeMarketplace
vscodeWithConfiguration vscodeExts2nix vscodeEnv;
}