1
0

default.nix 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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. ${lib.optionalString (builtins.hasAttr "branch" spec) ''
  28. if [ -d ${grammar}/queries ]; then
  29. ln -s ${grammar}/queries $out/queries
  30. fi
  31. ''}
  32. '';
  33. in
  34. builtins.mapAttrs buildTreesitterPlugin grammars