tree-sitter-grammars: consume scoped package set

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.
This commit is contained in:
Austin Horstman 2026-06-30 09:41:59 -05:00
commit f8a16a3068
No known key found for this signature in database
4 changed files with 11 additions and 23 deletions

View file

@ -15,9 +15,9 @@ let
# Usage:
# treesit-grammars.with-grammars (p: [ p.tree-sitter-bash p.tree-sitter-c ... ])
with-grammars = fn: grammarPackage (fn pkgs.tree-sitter.builtGrammars);
with-grammars = fn: grammarPackage (fn pkgs.tree-sitter-grammars.derivations);
with-all-grammars = grammarPackage pkgs.tree-sitter.allGrammars;
with-all-grammars = grammarPackage pkgs.tree-sitter-grammars.allGrammars;
in
{
inherit with-grammars with-all-grammars;

View file

@ -4,6 +4,7 @@
symlinkJoin,
vimUtils,
tree-sitter,
tree-sitter-grammars,
neovim,
neovimUtils,
runCommand,
@ -127,7 +128,7 @@ let
withPlugins =
f:
let
selectedGrammars = f (tree-sitter.builtGrammars // builtGrammars);
selectedGrammars = f (tree-sitter-grammars.derivations // builtGrammars);
grammarPlugins = map grammarToPlugin selectedGrammars;

View file

@ -4,32 +4,19 @@
linkFarm,
makeWrapper,
rustPlatform,
tree-sitter,
tree-sitter-grammars,
gitUpdater,
versionCheckHook,
}:
let
# based on https://github.com/NixOS/nixpkgs/blob/aa07b78b9606daf1145a37f6299c6066939df075/pkgs/development/tools/parsing/tree-sitter/default.nix#L85-L104
withPlugins =
grammarFn:
let
grammars = grammarFn tree-sitter.builtGrammars;
in
linkFarm "grammars" (
map (
drv:
let
name = lib.strings.getName drv;
in
{
name = "lib" + (lib.strings.removeSuffix "-grammar" name) + ".so";
path = "${drv}/parser";
}
) grammars
);
grammarToAttrSet = drv: {
name = "lib" + (lib.strings.removeSuffix "-grammar" (lib.strings.getName drv)) + ".so";
path = "${drv}/parser";
};
libPath = withPlugins (_: tree-sitter.allGrammars);
libPath = linkFarm "grammars" (map grammarToAttrSet tree-sitter-grammars.allGrammars);
in
rustPlatform.buildRustPackage rec {
pname = "diffsitter";

View file

@ -20302,7 +20302,7 @@ self: super: with self; {
"tree-sitter-sshclientconfig"
"tree-sitter-templ"
])
) pkgs.tree-sitter.builtGrammars
) pkgs.tree-sitter-grammars.derivations
)
);