Replies: 9 comments 6 replies
|
Thanks for your query, @bglgwyng 🙏 Let me try to answer your questions as best I can:
I do not recall anyone mentioning a NixOS/home-manager module before, for Topiary. Regardless, the most significant blocker for us at the moment would be manpower. I've made some light Nix changes in #1200, recently, but otherwise changes to our Nix code haven't been a priority.
Not that I'm aware of, I'm afraid.
If this would be useful to you, then I suspect it would also be useful to others. We'd certainly encourage and welcome any contributions, if you have the time. |
|
Keep an eye on https://birdeehub.github.io/nix-wrapper-modules/ Maybe someone will come contribute a proper wrapper module if they want one. Here's one from my config that I am messing with, but it needs a better set of queries options at least, it is kinda a sketch at the moment. https://github.com/BirdeeHub/birdeevim/blob/4f6a053a4424a127bbc8804d8de3e1a572d5994f/nix/topiary/module.nix This would then work as a standalone package, but also a nixos or home manager module if you want. This is more useful, because it means you can use it in development shells and tests for packages without evaluating nixos or home manager. But then still use it there too, with the same options. I might add it myself, but if I did it myself, I would probably end up spending way too much time on it and end up with a nix2nickel function and idk if im ready for all that just yet I already have a lot of stuff to do on this repo still XD Honestly what is at that link is probably almost good enough minus the queries option and maybe some prefetching changes if someone wanted to fix it up. |
|
Here I made a PoC of embedding configuration generated with Nix. You can test it with nix run .#topiary-cli-portable -- format exampledefaultEmbeddedConfig.nix is the Nix equivalent of Possible follow-ups:
|
|
I'm aware that the current implement is far from conventional one. I'm willing to modify the current implementation to make it more conventional. |
|
Apologies for the lack of communication from the Topiary core team on this effort, but just to say thank you for this 🙏 Otherwise, I suspect that this would be a useful feature, but I'm not equipped to review the details. Would anyone here (@bglgwyng, @BirdeeHub) object to me converting this into a GitHub discussion, where it might be better to talk about implementation strategies, before a PR is submitted? |
|
No problem! |
|
Besides my quirk experiment, the easiest approach is to just generate the |
|
I think the first version of this should probably stay deliberately conventional: a Home Manager module that generates Topiary configuration as files, and builds any grammars it manages into Nix store paths. interface along these lines: programs.topiary = {
enable = true;
# Defaults to this flake's Topiary package.
package = topiary.packages.${pkgs.system}.topiary-cli;
# Defaults to true. The module starts from Topiary's shipped language set,
# but rewrites grammar sources to store paths.
includeDefaultLanguages = true;
languages.<name> = {
extensions = [ "..." ];
indent = " "; # optional
grammar = {
symbol = "..."; # optional
# Either use an already-built grammar from nixpkgs/user packages...
package = pkgs.tree-sitter-grammars.tree-sitter-foo;
# ...or let the module build it with tree-sitter.buildGrammar.
source.git = {
url = "https://github.com/example/tree-sitter-foo";
rev = "...";
hash = "sha256-...";
subdir = null; # optional
};
};
query.formatting = ./formatting.scm;
# or:
# query.formatting.text = ''
# ...
# '';
};
};The important bit is that the generated The module should write: That keeps it aligned with Topiary's existing configuration model. By I would not wrap Topiary with This also makes the module useful without requiring Topiary changes. The existing Nix helpers already point in this direction: the current grammar-prefetching machinery effectively turns Git grammar sources into The implementation shape I would aim for:
|
|
I prototyped @ErinvanderVeen's suggestion here. |
Uh oh!
There was an error while loading. Please reload this page.
Topiary provides
lib.prefetchLanguages,lib.wrapWithConfig, andlib.gitHookas Nix building blocks, but there's no NixOS or home-manager module that offers a declarative interface for configuring Topiary — including custom language registration, grammar sources, and query files — through Nix module options.The docs note that building blocks are provided rather than complete solutions because the team is "unsure at this point of how people will use Topiary in their Nix code."
Two questions:
Has a NixOS/home-manager module been considered and intentionally deferred? If so, what are the blockers — unclear use cases, the Nickel/Nix boundary for grammar config, the
nixHashergonomics, or something else?Are there any known examples of users composing
lib.prefetchLanguages+lib.wrapWithConfiginto a module-like wrapper for custom language extension?My use case: when adding a custom language, you need to coordinate Nickel config (language mapping) and Nix (grammar compilation + prefetching). A module could unify both into a single Nix declaration. Happy to contribute if there's interest.
Thanks!
All reactions