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

95 lines
2.5 KiB
Nix
Raw Normal View History

2020-02-02 04:26:35 +01:00
{ stdenv, lib, buildEnv, writeShellScriptBin, fetchurl, vscode, unzip, jq }:
2017-08-12 06:27:17 +02: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,
2017-08-12 06:27:17 +02:00
configurePhase ? ":",
buildPhase ? ":",
dontPatchELF ? true,
dontStrip ? true,
buildInputs ? [],
...
}:
2020-05-30 04:21:04 +02:00
stdenv.mkDerivation ((removeAttrs a [ "vscodeExtUniqueId" ]) // {
2017-08-12 06:27:17 +02:00
name = "vscode-extension-${name}";
2017-08-12 06:27:17 +02:00
inherit vscodeExtUniqueId;
2017-08-12 06:27:17 +02:00
inherit configurePhase buildPhase dontPatchELF dontStrip;
installPrefix = "share/vscode/extensions/${vscodeExtUniqueId}";
buildInputs = [ unzip ] ++ buildInputs;
2017-08-12 06:27:17 +02: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 06:27:17 +02:00
'';
});
fetchVsixFromVscodeMarketplace = mktplcExtRef:
fetchurl((import ./mktplcExtRefToFetchArgs.nix mktplcExtRef));
2017-08-12 06:27:17 +02:00
buildVscodeMarketplaceExtension = a@{
name ? "",
src ? null,
2020-03-28 03:04:59 +01:00
vsix ? null,
2017-08-12 06:27:17 +02:00
mktplcRef,
...
}: assert "" == name; assert null == src;
2020-03-28 03:04:59 +01:00
buildVscodeExtension ((removeAttrs a [ "mktplcRef" "vsix" ]) // {
name = "${mktplcRef.publisher}-${mktplcRef.name}-${mktplcRef.version}";
2020-03-28 03:04:59 +01:00
src = if (vsix != null)
then vsix
else fetchVsixFromVscodeMarketplace mktplcRef;
vscodeExtUniqueId = "${mktplcRef.publisher}.${mktplcRef.name}";
2017-08-12 06:27:17 +02:00
});
mktplcRefAttrList = [
"name"
"publisher"
"version"
"sha256"
];
mktplcExtRefToExtDrv = ext:
buildVscodeMarketplaceExtension ((removeAttrs ext mktplcRefAttrList) // {
mktplcRef = ext;
});
2017-08-12 06:27:17 +02:00
extensionFromVscodeMarketplace = mktplcExtRefToExtDrv;
2017-08-12 06:27:17 +02:00
extensionsFromVscodeMarketplace = mktplcExtRefList:
builtins.map extensionFromVscodeMarketplace mktplcExtRefList;
2017-08-12 06:27:17 +02:00
vscodeWithConfiguration = import ./vscodeWithConfiguration.nix {
inherit lib extensionsFromVscodeMarketplace writeShellScriptBin;
vscodeDefault = vscode;
};
2020-05-30 04:21:04 +02:00
vscodeExts2nix = import ./vscodeExts2nix.nix {
inherit lib writeShellScriptBin;
vscodeDefault = vscode;
};
vscodeEnv = import ./vscodeEnv.nix {
2020-02-02 04:26:35 +01:00
inherit lib buildEnv writeShellScriptBin extensionsFromVscodeMarketplace jq;
vscodeDefault = vscode;
};
2020-05-30 04:21:04 +02:00
in
2017-08-12 06:27:17 +02:00
{
inherit fetchVsixFromVscodeMarketplace buildVscodeExtension
buildVscodeMarketplaceExtension extensionFromVscodeMarketplace
extensionsFromVscodeMarketplace
vscodeWithConfiguration vscodeExts2nix vscodeEnv;
}