diff --git a/flake.lock b/flake.lock index f14be3103..17615dd77 100644 --- a/flake.lock +++ b/flake.lock @@ -369,11 +369,11 @@ ] }, "locked": { - "lastModified": 1624890984, - "narHash": "sha256-RMQtTm4OoEc8BHWk4/Yfu1y4uHlG4HCP+DeC0J0zGqQ=", + "lastModified": 1627523399, + "narHash": "sha256-j9CgnUQpWcb8OB4LRzPW8BdxvmoROJptgptDlPA8Heo=", "owner": "berberman", "repo": "nvfetcher", - "rev": "d3efa8c58057dbcc1565dca3105d31d9f25fd5ca", + "rev": "fb8f2cc770ad3dd3e29d7ba3004692d4d53fba9b", "type": "github" }, "original": { diff --git a/pkgs/_sources/generated.nix b/pkgs/_sources/generated.nix index 0d13ac01e..ff97a43b4 100644 --- a/pkgs/_sources/generated.nix +++ b/pkgs/_sources/generated.nix @@ -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"; @@ -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."; }; } diff --git a/pkgs/default.nix b/pkgs/default.nix index 924a2300c..8eb07da08 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -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 { }); } diff --git a/pkgs/misc/vscode-extensions/default.nix b/pkgs/misc/vscode-extensions/default.nix new file mode 100644 index 000000000..589d751f7 --- /dev/null +++ b/pkgs/misc/vscode-extensions/default.nix @@ -0,0 +1,11 @@ +{ lib, vscode-utils, sources }: +let + inherit (vscode-utils) isVscodeExt mkVscodeExtensions; + + vscodeSources = lib.filterAttrs + (name: ext: if ext ? src then isVscodeExt ext.src.name else false) + sources; + + baseExtensions = mkVscodeExtensions vscodeSources; +in +baseExtensions diff --git a/pkgs/misc/vscode-extensions/vscode-utils.nix b/pkgs/misc/vscode-extensions/vscode-utils.nix new file mode 100644 index 000000000..640e90cfd --- /dev/null +++ b/pkgs/misc/vscode-extensions/vscode-utils.nix @@ -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); + + 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 + ; +} diff --git a/pkgs/sources.toml b/pkgs/sources.toml index f7af168e0..784dc33bd 100644 --- a/pkgs/sources.toml +++ b/pkgs/sources.toml @@ -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" }