Skip to content

vscode-extensions: detect vsix sources and generate packages automatically #353

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 31 additions & 1 deletion pkgs/_sources/generated.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
# This file was generated by nvfetcher, please do not modify it manually.
{ fetchgit, fetchurl }:
{
dotenv = {
pname = "dotenv";
version = "1.0.1";
src = fetchurl {
url = "https://open-vsx.org/api/mikestead/dotenv/1.0.1/file/mikestead.dotenv-1.0.1.vsix";
sha256 = "1ilp720bakyqwb29cxs1k7xsbqlill5j8dnk6bm839xzdvy394sk";
};
homepage = "https://github.com/mikestead/vscode-dotenv";
license = "mit";
description = "Support for dotenv file syntax";
};
manix = {
pname = "manix";
version = "d08e7ca185445b929f097f8bfb1243a8ef3e10e4";
Expand All @@ -12,6 +23,25 @@
leaveDotGit = false;
sha256 = "1b7xi8c2drbwzfz70czddc4j33s7g1alirv12dwl91hbqxifx8qs";
};

};
nixpkgs-fmt = {
pname = "nixpkgs-fmt";
version = "0.0.1";
src = fetchurl {
url = "https://B4dM4n.gallery.vsassets.io/_apis/public/gallery/publisher/B4dM4n/extension/nixpkgs-fmt/0.0.1/assetbyname/Microsoft.VisualStudio.Services.VSIXPackage";
sha256 = "1gvjqy54myss4w1x55lnyj2l887xcnxc141df85ikmw1gr9s8gdz";
};
license = "mit";
};
rust = {
pname = "rust";
version = "0.7.8";
src = fetchurl {
url = "https://open-vsx.org/api/rust-lang/rust/0.7.8/file/rust-lang.rust-0.7.8.vsix";
sha256 = "02mpqpyk6aid6s7byqzh8s1fd2mgzcpl2rpyri0fgakc67bsnyz6";
};
homepage = "https://github.com/rust-lang/rls-vscode";
license = "[ \"mit\", \"asl20\" ]";
description = "Rust for Visual Studio Code (powered by Rust Language Server/Rust Analyzer). Provides lints, code completion and navigation, formatting and more.";
};
}
4 changes: 4 additions & 0 deletions pkgs/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@ final: prev: {
# keep sources this first
sources = prev.callPackage (import ./_sources/generated.nix) { };
# then, call packages with `final.callPackage`

vscode-utils = prev.vscode-utils // (prev.callPackage ./misc/vscode-extensions/vscode-utils.nix { });

vscode-extensions = prev.vscode-extensions // (final.callPackage ./misc/vscode-extensions { });
}
11 changes: 11 additions & 0 deletions pkgs/misc/vscode-extensions/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{ lib, vscode-utils, sources }:
let
inherit (vscode-utils) isVscodeExt mkVscodeExtensions;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those look like convenience library functions that we might want to discuss adding in digga?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or alternatively a divnix/vsext (to decouple release cycles)!!!


vscodeSources = lib.filterAttrs
(name: ext: if ext ? src then isVscodeExt ext.src.name else false)
sources;

baseExtensions = mkVscodeExtensions vscodeSources;
in
baseExtensions
94 changes: 94 additions & 0 deletions pkgs/misc/vscode-extensions/vscode-utils.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
{ lib
, vscode-utils
, vscode
, namespace ? false
}:

with lib;

let
isVsix = hasSuffix ".vsix";

isVsixPackage = hasSuffix ".VSIXPackage";

isVscodeExt = name: (isVsix name) || (isVsixPackage name);
Comment on lines +10 to +14
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!


isNaiveJSONList = string: (hasPrefix "[" string) && (hasSuffix "]" string);

toJSONString = string:
if isNaiveJSONList string
then string
else ''"${string}"'';

mkVscodeExtUniqueId = ext:
let uniqueIds =
if isVsix ext.src.name
then splitString "." (getName ext.src.name)
else
builtins.match
# 1st & 2nd match: publisher
# 3rd match: name
"https://(.*).gallery.vsassets.io/_apis/public/gallery/publisher/(.*)/extension/(.*)/${ext.version}/assetbyname/Microsoft.VisualStudio.Services.VSIXPackage"
(head ext.src.urls);
in
{ publisher = head uniqueIds; pname = last uniqueIds; };

mkVscodeExtMetaLink = name: publisher: pname: { openVsxPath ? "/", vscodeMarketplacePath ? "/" }:
if isVsix name
then "https://open-vsx.org/extension/${publisher}/${pname}${openVsxPath}"
else "https://marketplace.visualstudio.com/items/${publisher}.${pname}${vscodeMarketplacePath}";

mkVscodeMetaOption = ext:
if isVsix ext.src.name
then { inherit (ext) homepage description; }
else { };

mkVscodeExtension = ext: publisher: pname:
vscode-utils.buildVscodeExtension ((builtins.removeAttrs ext [ "pname" "src" "version" "homepage" "description" ]) // rec {
inherit (ext) version;

name = "${publisher}-${pname}-${version}";

vscodeExtUniqueId = "${publisher}.${pname}";

src = "${publisher}-${pname}.zip";

preUnpack = ''ln -s "${ext.src}" $src'';

meta = with lib; {
inherit (vscode.meta) platforms;
downloadPage = mkVscodeExtMetaLink ext.src.name publisher pname { };
changelog = mkVscodeExtMetaLink ext.src.name publisher pname {
openVsxPath = "/changes";
vscodeMarketplacePath = "/changelog";
};
license = assert asserts.assertMsg (ext ? license) "Specify a license for ${vscodeExtUniqueId} VS Code extension!";
forEach
(toList (builtins.fromJSON (toJSONString ext.license)))
(license: licenses."${license}");
maintainers =
if ext ? maintainers
then
forEach
(toList (builtins.fromJSON ext.maintainers))
(maintainer: maintainers."${maintainer}")
else [ maintainers.danielphan2003 ];
} // (mkVscodeMetaOption ext);
});

mkVscodeExtensions = sources:
mapAttrs'
(name: ext:
let inherit (mkVscodeExtUniqueId ext) publisher pname; in
nameValuePair
"${optionalString namespace "${publisher}."}${name}" # follows user-defined source name
(mkVscodeExtension ext publisher pname))
sources;
in
{
inherit
isVsix isVscodeExt isVsixPackage
mkVscodeExtUniqueId mkVscodeExtMetaLink
mkVscodeExtension mkVscodeExtensions
;
}
15 changes: 15 additions & 0 deletions pkgs/sources.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,18 @@
[manix]
src.git = "https://github.com/mlvzk/manix"
fetch.github = "mlvzk/manix"

[dotenv]
src.openvsx = "mikestead.dotenv"
fetch.openvsx = "mikestead.dotenv"
passthru = { license = "mit", homepage = "https://github.com/mikestead/vscode-dotenv", description = "Support for dotenv file syntax" }

[rust]
src.openvsx = "rust-lang.rust"
fetch.openvsx = "rust-lang.rust"
passthru = { license = '[ "mit", "asl20" ]', homepage = "https://github.com/rust-lang/rls-vscode", description = "Rust for Visual Studio Code (powered by Rust Language Server/Rust Analyzer). Provides lints, code completion and navigation, formatting and more." }

[nixpkgs-fmt]
src.vsmarketplace = "B4dM4n.nixpkgs-fmt"
fetch.vsmarketplace = "B4dM4n.nixpkgs-fmt"
passthru = { license = "mit" }