Skip to content

tree-sitter: make tree-sitter-grammars an overridable scope #537058

Merged
khaneliman merged 4 commits into
NixOS:masterfrom
khaneliman:tree-sitter-grammar-scope
Jul 5, 2026
Merged

tree-sitter: make tree-sitter-grammars an overridable scope #537058
khaneliman merged 4 commits into
NixOS:masterfrom
khaneliman:tree-sitter-grammar-scope

Conversation

@khaneliman

@khaneliman khaneliman commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Turn pkgs.tree-sitter-grammars into the single, override-aware source of tree-sitter grammars, and route the existing consumers through it.

Alternative solution to (technically we could combine them and use the other as a more "backwards-compatible" drop in.
Closes #536475

Things done

@khaneliman khaneliman force-pushed the tree-sitter-grammar-scope branch from 7392927 to aaae998 Compare June 30, 2026 13:12
@khaneliman khaneliman requested a review from RossSmyth June 30, 2026 13:16
@nixpkgs-ci nixpkgs-ci Bot requested review from a team, 90-008, aciceri, amaanq, bbigras, danth, figsoda and uncenter June 30, 2026 13:18
@nixpkgs-ci nixpkgs-ci Bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux. 6.topic: python Python is a high-level, general-purpose programming language. 6.topic: emacs Text editor 6.topic: vim Advanced text editor 6.topic: tree-sitter Tree-sitter is a parser generator tool and an incremental parsing library. labels Jun 30, 2026
@khaneliman khaneliman force-pushed the tree-sitter-grammar-scope branch 3 times, most recently from ddce663 to 2299500 Compare June 30, 2026 16:05
@khaneliman khaneliman changed the title tree-sitter: expose scoped grammar package set tree-sitter: make tree-sitter-grammars an overridable scope Jun 30, 2026

@RossSmyth RossSmyth left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I understand better on how it is structured, there was/is is scope, but it has no relationship to allGrammars and grammars so overrides don't actually do anything. Few observations and questions.

# `.allGrammars` list of non-broken grammar derivations
# `.withPlugins` build a grammar link farm
*/
grammarsScope = lib.makeScope newScope (

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should probably just be called grammars, no need to make people wonder "what is a scope" if they have no need to be aware.

Comment thread pkgs/by-name/tr/tree-sitter/package.nix Outdated
grammarsScope
withPlugins
allGrammars
;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The problem is that grammars and grammarScope are not actually related here. If I were making it, I would only expose grammar, which would be a scope.

Then you need to put a fix between allGrammars and grammars so that when grammars is overriden, allGrammars changes too. Currently it does not as you just make a copy of the unoveridden scope.

The above is similar to how python3Packges and typstPackages works, just without allGrammars.

Can alias grammarsScope to grammars so it's not a breaking change.

Suggested change
passthru = {
inherit
buildGrammar
builtGrammars
withPlugins
allGrammars
;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think there are two reasonable priorities here.

Using tree-sitter.grammars for the built scope matches the Python/Typst package-set shape and makes the public extension point tidy. The cost is that tree-sitter.grammars currently exposes source specs, so external consumers using that passthru could break.

Keeping tree-sitter.grammars as source specs and putting the built scope at something like tree-sitter.grammarPackages is a little less elegant, but it preserves the existing public meaning while still letting tree-sitter-grammars = recurseIntoAttrs tree-sitter.grammarPackages and making overrides compose.

Given the chance of external consumers, I lean toward the backwards-compatible shape unless we think the tree-sitter.grammars source-spec passthru is safe to repurpose.

@khaneliman khaneliman force-pushed the tree-sitter-grammar-scope branch from 2299500 to 7a301dd Compare July 1, 2026 03:05
pkgs.tree-sitter-grammars was a flat recurseIntoAttrs of builtGrammars. Point it at the existing grammarsScope so it carries .overrideScope, and add grammar-only views to that scope — derivations (attrset), allGrammars (non-broken list), and withPlugins — so it stays iterable alongside the package-set helpers. builtGrammars remains the stock, non-overridden 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.
Apply Helix's locked grammar overlay to pkgs.tree-sitter-grammars so global grammar-scope overrides compose through the public extension point.
Document overrideScope as the supported extension point and the scoped grammar-only views (derivations, allGrammars, withPlugins) that consumers should iterate.
@khaneliman khaneliman force-pushed the tree-sitter-grammar-scope branch from 7a301dd to 0a53614 Compare July 1, 2026 03:07
@aciceri

aciceri commented Jul 1, 2026

Copy link
Copy Markdown
Member

nixpkgs-review result

Generated using nixpkgs-review-gha (da739d6)

Command: nixpkgs-review pr 537058
Commit: 0a53614dbbd241a3f99ddb0eadaa7655092a8bd9 (subsequent changes)
Merge: f3d0cb9d4c38915de2e7222da6861a9a2eefa6bb

Logs: https://github.com/aciceri/nixpkgs-review-gha/actions/runs/28519406230/attempts/1


x86_64-linux

No rebuilds


aarch64-linux

No rebuilds


x86_64-darwin

No rebuilds


aarch64-darwin

No rebuilds

@aciceri aciceri left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I like this, I wish it had been already here when I packages helix's grammars, happy to see that someone implemented it!
No derivations are rebuilt so we are sure that it wouldn't cause any harm to grammars consumers, in my opinion it's already good enough to be merged and further adjustments can be done in separate PRs.

Comment thread pkgs/by-name/he/helix/package.nix
@nixpkgs-ci nixpkgs-ci Bot added 12.approvals: 1 This PR was reviewed and approved by one person. 12.approved-by: package-maintainer This PR was reviewed and approved by a maintainer listed in any of the changed packages. labels Jul 1, 2026
@khaneliman khaneliman added this pull request to the merge queue Jul 5, 2026
Merged via the queue into NixOS:master with commit 08a5b50 Jul 5, 2026
34 of 36 checks passed
@khaneliman khaneliman deleted the tree-sitter-grammar-scope branch July 5, 2026 03:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.topic: emacs Text editor 6.topic: python Python is a high-level, general-purpose programming language. 6.topic: tree-sitter Tree-sitter is a parser generator tool and an incremental parsing library. 6.topic: vim Advanced text editor 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux. 12.approvals: 1 This PR was reviewed and approved by one person. 12.approved-by: package-maintainer This PR was reviewed and approved by a maintainer listed in any of the changed packages.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants