mirror of
https://github.com/helix-editor/helix.git
synced 2024-08-17 06:40:47 +03:00
grammars.nix: use github type for fetchTree where possible (#1872)
This commit is contained in:
parent
511f37c736
commit
b63b37d5a0
17
grammars.nix
17
grammars.nix
@ -10,16 +10,31 @@ let
|
||||
isGitGrammar = (grammar:
|
||||
builtins.hasAttr "source" grammar && builtins.hasAttr "git" grammar.source
|
||||
&& builtins.hasAttr "rev" grammar.source);
|
||||
isGitHubGrammar = grammar: lib.hasPrefix "https://github.com" grammar.source.git;
|
||||
toGitHubFetcher = url: let
|
||||
match = builtins.match "https://github\.com/([^/]*)/([^/]*)/?" url;
|
||||
in {
|
||||
owner = builtins.elemAt match 0;
|
||||
repo = builtins.elemAt match 1;
|
||||
};
|
||||
gitGrammars = builtins.filter isGitGrammar languagesConfig.grammar;
|
||||
buildGrammar = grammar:
|
||||
let
|
||||
source = builtins.fetchTree {
|
||||
gh = toGitHubFetcher grammar.source.git;
|
||||
sourceGit = builtins.fetchTree {
|
||||
type = "git";
|
||||
url = grammar.source.git;
|
||||
rev = grammar.source.rev;
|
||||
ref = grammar.source.ref or "HEAD";
|
||||
shallow = true;
|
||||
};
|
||||
sourceGitHub = builtins.fetchTree {
|
||||
type = "github";
|
||||
owner = gh.owner;
|
||||
repo = gh.repo;
|
||||
inherit (grammar.source) rev;
|
||||
};
|
||||
source = if isGitHubGrammar grammar then sourceGitHub else sourceGit;
|
||||
in stdenv.mkDerivation rec {
|
||||
# see https://github.com/NixOS/nixpkgs/blob/fbdd1a7c0bc29af5325e0d7dd70e804a972eb465/pkgs/development/tools/parsing/tree-sitter/grammar.nix
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user