From b63b37d5a09ffb7e9703a046fbf42f668303e262 Mon Sep 17 00:00:00 2001 From: Max Date: Mon, 28 Mar 2022 23:50:18 +0200 Subject: [PATCH] grammars.nix: use github type for fetchTree where possible (#1872) --- grammars.nix | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/grammars.nix b/grammars.nix index bd2c95cc1..bcd2c2fa9 100644 --- a/grammars.nix +++ b/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