1
0
Fork 1
mirror of https://github.com/NixOS/nixpkgs.git synced 2024-12-11 07:04:28 +00:00
nixpkgs/pkgs/misc/vscode-extensions/vscode-utils.nix

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