Change:
<ins> #!/usr/bin/env nix-shell #! nix-shell ../../../../../../. -i python3 -p python3 -p nix from os.path import ( dirname, abspath, join, ) from typing import ( List, Any, ) import subprocess import json import sys import os def fmt_grammar(grammar: str) -> str: return "tree-sitter-" + grammar def eval_expr(nixpkgs: str, expr: str) -> Any: p = subprocess.run( [ "nix-instantiate", "--json", "--eval", "--expr", ("with import %s {}; %s" % (nixpkgs, expr)), ], check=True, stdout=subprocess.PIPE, ) return json.loads(p.stdout) def check_grammar_exists(nixpkgs: str, grammar: str) -> bool: return eval_expr( nixpkgs, f'lib.hasAttr "{fmt_grammar(grammar)}" tree-sitter-grammars' ) def build_attr(nixpkgs, attr: str) -> str: return ( subprocess.run( ["nix-build", "--no-out-link", nixpkgs, "-A", attr], check=True, stdout=subprocess.PIPE, ) .stdout.decode() .strip() ) if __name__ == "__main__": cwd = dirname(abspath(__file__)) nixpkgs = abspath(join(cwd, "../../../../../..")) src_dir = build_attr(nixpkgs, "emacs.pkgs.tree-sitter-langs.src") existing: List[str] = [] grammars = os.listdir(join(src_dir, "repos")) for g in grammars: exists = check_grammar_exists(nixpkgs, g) if exists: existing.append(fmt_grammar(g)) else: sys.stderr.write("Missing grammar: " + fmt_grammar(g) + "n") sys.stderr.flush() with open(join(cwd, "default-grammars.json"), mode="w") as f: json.dump(sorted(existing), f, indent=2) f.write("n") </ins>

Discussion:
Describe the bug The Emacs packages for don't successfully load. To Reproduce Run a from the following : After opening Emacs from inside the and running , we get the following: Expected behavior The packages should be properly loaded, and they should offer syntax-highlighting for select languages. Notify maintainers No one has any particular responsibility for this package. But might be interested in this. Metadata Please run and paste the result.
I'm currently using this, but it stills need some work. Languages grammar are downloaded instead of being built (each language should have it's own separate nix package), and I'm not happy about the but if the grammar bins are in directory will put them in the .
I marked this as stale due to inactivity. &rarr;
Unstale
facing the same issue
Same. What's going on with this issue?
So, I've been looking into this a bit and kind of understand what should be done, but haven't been able to create enough code for a working PR yet. So, basically what you want is to build a rust package from here: The result of the build is and this needs to be built as a dependency for so the file is available for it as . I think it should be enough to link whatever file gets compiled from to the if I read the code correctly. Then, the next is to link all the compiled tree-sitter grammars for the emacs package to find, something copied from how the neovim plugin does this: I'm not completely sure where to build all these packages and I'm running out of my personal time to get this working together. What I see in the current state is many packages linking as a dependency, but is just building the emacs package, not using to build whatever is in the directory and linking the resulting library for the lisp libraries. And the grammars are already in the nixpkgs, you just need to link them to a place where the emacs tree-sitter plugin can find them.
Hey all. I'm still working on fixing this due to me needing tree-sitter for my emacs setup and wanting to understand nix more. Here's the work so far: It now compiles the rust module correctly, and uses the linking strategy from for the languages.

It still tries to download files from github, so I either don't link the files to the correct location, or I should patch a method to prevent the download process. I think the best solution would be to use the grammars already available in the monorepo the same way as does. My first try with them was with , but some of them won't work together with the emacs library due to licensing issues. And I also got myself to the download problem, but I think this is not due to files not being the pre-compiled ones from github, but again about some linking issues. If somebody wants to try this out and give me feedback, I'm all ears. I will probably spend some Christmas holiday spare time to make the PR happen. It is very close already.
I made a PR and now it works at least on my NixOS laptop. It would still be nice if we could either utilize the grammars already available in nix, or at least we'd be able to compile them in the derivation instead of just downloading the binaries. I'd be happy if you could try this out and see if it works for you.