diff --git a/pkgs/applications/editors/vscode/extensions/openvsxExtRefToFetchArgs.nix b/pkgs/applications/editors/vscode/extensions/openvsxExtRefToFetchArgs.nix new file mode 100644 index 0000000000000..9e9d1f1101f57 --- /dev/null +++ b/pkgs/applications/editors/vscode/extensions/openvsxExtRefToFetchArgs.nix @@ -0,0 +1,12 @@ +{ publisher, name, version, arch ? "", sha256 ? "" }: +let + url = + if arch == "" + then "https://open-vsx.org/api/${publisher}/${name}/${version}/file/${publisher}.${name}-${version}.vsix" + else "https://open-vsx.org/api/${publisher}/${name}/${arch}/${version}/file/${publisher}.${name}-${version}.vsix"; +in +{ + inherit url; + sha256 = sha256; + name = "${publisher}-${name}.zip"; +} diff --git a/pkgs/applications/editors/vscode/extensions/vscode-utils.nix b/pkgs/applications/editors/vscode/extensions/vscode-utils.nix index 8f0112e5f608a..fc93c3680d7e6 100644 --- a/pkgs/applications/editors/vscode/extensions/vscode-utils.nix +++ b/pkgs/applications/editors/vscode/extensions/vscode-utils.nix @@ -45,6 +45,9 @@ let fetchVsixFromVscodeMarketplace = mktplcExtRef: fetchurl (import ./mktplcExtRefToFetchArgs.nix mktplcExtRef); + fetchVsixFromOpenVsx = mktplcExtRef: + fetchurl (import ./openvsxExtRefToFetchArgs.nix mktplcExtRef); + buildVscodeMarketplaceExtension = a@{ name ? "", src ? null, @@ -60,6 +63,21 @@ let vscodeExtUniqueId = "${mktplcRef.publisher}.${mktplcRef.name}"; }); + buildOpenVsxExtension = a@{ + name ? "", + src ? null, + vsix ? null, + mktplcRef, + ... + }: assert "" == name; assert null == src; + buildVscodeExtension ((removeAttrs a [ "mktplcRef" "vsix" ]) // { + name = "${mktplcRef.publisher}-${mktplcRef.name}-${mktplcRef.version}"; + src = if (vsix != null) + then vsix + else fetchVsixFromOpenVsx mktplcRef; + vscodeExtUniqueId = "${mktplcRef.publisher}.${mktplcRef.name}"; + }); + mktplcRefAttrList = [ "name" "publisher" @@ -73,16 +91,24 @@ let mktplcRef = builtins.intersectAttrs (lib.genAttrs mktplcRefAttrList (_: null)) ext; }); + openvsxExtRefToExtDrv = ext: + buildOpenVsxExtension (removeAttrs ext mktplcRefAttrList // { + mktplcRef = builtins.intersectAttrs (lib.genAttrs mktplcRefAttrList (_: null)) ext; + }); + extensionFromVscodeMarketplace = mktplcExtRefToExtDrv; extensionsFromVscodeMarketplace = mktplcExtRefList: builtins.map extensionFromVscodeMarketplace mktplcExtRefList; + extensionFromOpenVsx = openvsxExtRefToExtDrv; + extensionsFromOpenVsx = mktplcExtRefList: + builtins.map extensionFromOpenVsx mktplcExtRefList; + vscodeWithConfiguration = import ./vscodeWithConfiguration.nix { inherit lib extensionsFromVscodeMarketplace writeShellScriptBin; vscodeDefault = vscode; }; - vscodeExts2nix = import ./vscodeExts2nix.nix { inherit lib writeShellScriptBin; vscodeDefault = vscode; @@ -95,7 +121,9 @@ let in { inherit fetchVsixFromVscodeMarketplace buildVscodeExtension - buildVscodeMarketplaceExtension extensionFromVscodeMarketplace - extensionsFromVscodeMarketplace - vscodeWithConfiguration vscodeExts2nix vscodeEnv; + buildVscodeMarketplaceExtension extensionFromVscodeMarketplace + extensionsFromVscodeMarketplace + vscodeWithConfiguration vscodeExts2nix vscodeEnv; + inherit fetchVsixFromOpenVsx buildOpenVsxExtension + openvsxExtRefToExtDrv extensionFromOpenVsx; }