Problem with Neovim Treesitter Go on Nix

I created an issue on the nvim-treesitter tracker but wanted to ask around here as well. I can’t use go.so files compiled through Nix, but things work if let the nvim-treesitter plugin do the compilation in nix-shell -p gcc. Please see the issue for details. I wanted to package the parsers as Vim plugins in Nixpkgs but before that these things should at least work on NixOS :frowning:

@teto tagging you because I know you use more or less the same combination although you reuse the builtGrammars. Funnily, those too fail for me in the case of Go.

There’s a lockfile where certain working revisions of the parsers are pinned. This helps maintain ABI compatibility. Using the revision from the lockfile for go solved my issue.

dont know for go but I’ve fixed recently (<1 month) C and bash grammars in nixpkgs.

Last week, @vigoux merged a patch in neovim that checks for the treesitter ABI to give nicer error messages.

I am trying to improve the (neo)vim support into nixos. For now it’s easier to rely on modules but eventually I would like to be able to generate a runtime without. Here are some ways to install the grammars in the correct place:

# with home-manager
  home.file."${config.xdg.configHome}/nvim/parser/c.so".source = "${pkgs.tree-sitter.builtGrammars.c}/parser";

# when using the new nixos neovim module
    runtime."parser/c.so".source = "${pkgs.tree-sitter.builtGrammars.c}/parser";

1 Like

@teto problem here is that it is not using the treesitter’r own locked version –
an alternate solution – not pretty but works:

I personally have this in my dotfiles

  grammarNix = makeGrammar {
    parserName = "nix";
    includedFiles = [ "parser.c" "scanner.c" ];
    src = "${builtins.fetchGit {
      "url" = "https://github.com/cstrahan/tree-sitter-nix";
      "ref" = "master";
      "rev" = "d5287aac195ab06da4fe64ccf93a76ce7c918445";
      }}/src";
  };

  makeGrammar =
    { includedFiles
    , parserName
    , src
    , name ? parserName
    , version ? "latest"
    }:
    pkgs.vimUtils.buildVimPluginFrom2Nix {
      version = version;
      name = "nvim-treesitter-${name}";
      src = src;
      buildPhase = ''
        runHook preBuild
        mkdir -p parser/
        ${pkgs.gcc}/bin/gcc -o parser/${parserName}.so -I$src/ ${builtins.concatStringsSep " " includedFiles}  -shared  -Os -lstdc++ -fPIC
        runHook postBuild
      '';
    };

and I just manually update the rev with what I get from nvim-treesitter/lockfile.json at 788d212ab3d249a673160779528fe6b03eff93a4 · nvim-treesitter/nvim-treesitter · GitHub

I’d like to at some point upstream something where nvim-treesitter and the grammars are one derivation that you can configure because there’s a dependency between the parsers and nvim-treesitter. Honestly, there’s even a dependency between nvim-treesitter and neovim as far as I understand it.

1 Like

Some of these issues are due to the unstable aspect of nvim-treesitter etc.
Upstreaming this could be useful in
GitHub - nix-community/neovim-nightly-overlay: [maintainer=@mjlbach] for instance

Yet another solution, this one uses the lockfile too:
https://github.com/hurricanehrndz/nixcfg/tree/main/nix/pkgs/nvim-ts-grammars

1 Like

Yet another implementation; dotfiles/default.nix at 0bb5bbb388031283a604f64c2e9afe94e1f4cd55 · willruggiano/dotfiles · GitHub

:slight_smile: