mirror of
https://github.com/NixOS/nixpkgs.git
synced 2026-07-06 17:13:24 -05:00
Read grammars from the public tree-sitter-grammars scope, via its derivations and allGrammars views, in emacs treesit-grammars, diffsitter, the python bindings, and nvim-treesitter, instead of tree-sitter.builtGrammars. An overrideScope override of the set now propagates to these packages.
24 lines
716 B
Nix
24 lines
716 B
Nix
{ pkgs, lib }:
|
|
|
|
let
|
|
libExt = pkgs.stdenv.hostPlatform.extensions.sharedLibrary;
|
|
grammarToAttrSet = drv: {
|
|
name = "lib/lib${
|
|
lib.strings.replaceStrings [ "_" ] [ "-" ] (
|
|
lib.strings.removeSuffix "-grammar" (lib.strings.getName drv)
|
|
)
|
|
}${libExt}";
|
|
path = "${drv}/parser";
|
|
};
|
|
|
|
grammarPackage = grammars: pkgs.linkFarm "emacs-treesit-grammars" (map grammarToAttrSet grammars);
|
|
|
|
# Usage:
|
|
# treesit-grammars.with-grammars (p: [ p.tree-sitter-bash p.tree-sitter-c ... ])
|
|
with-grammars = fn: grammarPackage (fn pkgs.tree-sitter-grammars.derivations);
|
|
|
|
with-all-grammars = grammarPackage pkgs.tree-sitter-grammars.allGrammars;
|
|
in
|
|
{
|
|
inherit with-grammars with-all-grammars;
|
|
}
|