tree-sitter-grammars: pin rev for unstable grammars (#491704)

This commit is contained in:
Matthieu Coudron
2026-02-18 13:36:54 +01:00
committed by GitHub
2 changed files with 373 additions and 183 deletions
@@ -40,6 +40,9 @@ in
lib.mapAttrs' (
language: attrs:
let
source = lib.optionalAttrs (attrs ? url) (parseUrl attrs.url);
in
lib.nameValuePair "tree-sitter-${language}" (
{
# Default to the source attr name as the language
@@ -55,7 +58,7 @@ lib.mapAttrs' (
if (isUnstable attrs.version) then
[
"--version"
"branch"
"branch${lib.optionalString (source ? ref) "=${source.ref}"}"
]
else
[
@@ -70,7 +73,6 @@ lib.mapAttrs' (
// lib.optionalAttrs (attrs ? url && attrs ? hash) {
src =
let
source = parseUrl attrs.url;
fetch = lib.getAttr source.type {
github = fetchFromGitHub;
gitlab = fetchFromGitLab;
@@ -78,19 +80,26 @@ lib.mapAttrs' (
codeberg = fetchFromCodeberg;
# NOTE: include other types here as required
};
rev =
if isUnstable attrs.version then
attrs.rev
or (throw "tree-sitter grammar '${language}': unstable version requires a pinned 'rev' attribute")
else
source.ref or "v${attrs.version}";
in
fetch {
inherit (source)
owner
repo
;
rev = source.ref or "v${attrs.version}";
inherit rev;
inherit (attrs) hash;
};
}
// removeAttrs attrs [
"url"
"hash"
"rev"
]
)
) grammar-sources
File diff suppressed because it is too large Load Diff