emacs-twist / twist.nix

Build an entire Emacs configuration as a Nix package in a pure, reproducible way
GNU General Public License v3.0
66 stars 6 forks source link

feat(build): add treesitter support #164

Closed jordanisaacs closed 2 days ago

jordanisaacs commented 3 days ago

Add builtin treesitter support. Automatically enabled/disabled when emacs is built with treesitter.

akirak commented 3 days ago

Thanks for this PR, but I won't accept it.

This twist.nix repository isn't trying to do everything to make Emacs configuration easy. I would prefer keeping things separate wherever possible.

In this case, you can generate an extra configuration for loading the tree-sitter grammars without tweaking the library:

  pkgs.writeText "init-treesit.el" ''
    (add-to-list 'treesit-extra-load-path  "${
      pkgs.linkFarm "treesit-grammars"
      (
        map (drv: {
          # Some grammars don't contain "tree-sitter-" as the prefix,
          # so add it explicitly.
          name = "libtree-sitter-${
            lib.pipe (lib.getName drv) [
              (lib.removeSuffix "-grammar")
              (lib.removePrefix "tree-sitter-")
            ]
          }${
            pkgs.stdenv.targetPlatform.extensions.sharedLibrary
          }";
          path = "${drv}/parser";
        })
        treeSitterGrammars
      )
    }/")
  ''

I also don't want to depend on a function/package from elisp-packages directory in nixpkgs. They have been doing great work, but twist.nix should depend only on the following external Nix code for stability:

Duplication is fine, so some of the code in this repository implements the same logic as the Emacs infrastructure in nixpkgs. If something gets outdated, just send a PR to this repository. That's a maintenance work.

Nevertheless, the tree-sitter support is now crucial for Emacs users, so it may make sense to add the above function to this repository (probably under lib output of the flake). Sorry for your inconvenience, but this is how the project is currently being run.

jordanisaacs commented 3 days ago

Totally understand. The reason for this was mostly that I couldn't do this out of tree. Since treesitter load paths (imo) belong in site-start but you can't pass it in.

Also for background I used the nixpkgs treesitter function since treesitter grammar versions are tied to the emacs package version itself.

Would you accept a PR that allows arbitrary extra elisp code for site-start, e.g. extraSiteStartElisp?