1
0

default.nix 912 B

1234567891011121314151617181920212223242526272829303132
  1. { lib, runCommand, fetchFromGitHub, tree-sitter }:
  2. let
  3. grammars = builtins.fromJSON (builtins.readFile ./grammars.json);
  4. buildTreesitterPlugin = name: spec:
  5. let
  6. nameParts = builtins.split "/" (spec.repo or "tree-sitter/tree-sitter-${name}");
  7. owner = builtins.head nameParts;
  8. repo = builtins.elemAt nameParts 2;
  9. grammar = tree-sitter.buildGrammar ({
  10. language = name;
  11. version = "0.0.0+rev=${spec.rev}";
  12. src = fetchFromGitHub {
  13. inherit owner repo;
  14. inherit (spec) rev sha256;
  15. };
  16. } // lib.optionalAttrs (builtins.hasAttr "path" spec) {
  17. location = spec.path;
  18. });
  19. in
  20. runCommand "tree-sitter-${name}" {
  21. passthru = {
  22. inherit grammar;
  23. };
  24. } ''
  25. mkdir -p $out/parser
  26. ln -s ${grammar}/parser $out/parser/${name}.so
  27. '';
  28. in
  29. builtins.mapAttrs buildTreesitterPlugin grammars