Skip to content

LSPs stop working when running in a devenv environment #268

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
aloysb opened this issue Apr 25, 2025 · 5 comments
Open

LSPs stop working when running in a devenv environment #268

aloysb opened this issue Apr 25, 2025 · 5 comments
Labels
question Further information is requested stale

Comments

@aloysb
Copy link

aloysb commented Apr 25, 2025

Hey, love the project! thanks for all the work on this!

I'm hitting one issue that prevents me from switching to nix cats for good: none of my LSPs (e.g., elixir-ls) are working when inside a devenv shell.

For example:

  • If I delete the .devenv directory, everything works fine, the LSPs run as expected.
  • As soon as I enter a devenv shell, all LSPs stop working (Elixir, Tailwind, Go, etc.).
  • You can reproduce this by running devenv init in a repo.

It feels like a PATH issue or something about the shell environment devenv sets up, but I haven’t been able to pinpoint it, and the logs haven't been helpful.

I've noticed that the path (such as elixir-ls) are different when .devenv is present.

I understand this repo may not support devenv, but I’m wondering if you’ve run into this before or could offer any debugging tips.

It’s the last hurdle I need to fully switch to nix cats and devenv.

Thanks in advance!

@aloysb aloysb changed the title Issues with devenv LSPs stop working when running in a devenv environment Apr 25, 2025
@aloysb
Copy link
Author

aloysb commented Apr 25, 2025

{
  pkgs,
  lib,
  config,
  inputs,
  ...
}: {
  packages = with pkgs; [
    git
    // ... Add lsp here
    tailwindcss-language-server
    elixir-ls
  ];
  languages = {
    erlang.enable = true;
    elixir.enable = true;
  };
  env = {
    DATABASE_URL = "..."
  };
  dotenv.enable = true;
  services.postgres = {
    enable = true;
    initialDatabases = [];
....
  };
}

As a workaround, after a few hours of digging around I found that adding the LSP to the devenv fixes the issues.
Not ideal, but if you have a better idea I'm willing to hear!

It definitively smells like path issue, which is odd as the LSP do show up in nvim if I do !which elixir-ls.

@BirdeeHub
Copy link
Owner

BirdeeHub commented Apr 25, 2025

So, installing lsps to the dev shell is actually very common as sometimes the version of the language used in the project is different fro the one you installed in your nvim.

NixCats suffixes the path with the items in lspsAndRuntimeDeps by default so that by default nvim will inherit the lsp from the shelll instead of itself if provided, and otherwise fall back to the items provided by nixCats.

Unfortunately, this also means people can also run into environment issues by default.

You should double check that the shell isn't adding things you aren't expecting (many of the devenv options do actually install the lsp alongside the language by default)

First thing to try

you can make nixCats prefix the path with its items instead of suffix. This should make the ones provided by nixCats always win out over ones provided from other sources. You can either change the default for all items in lspsAndRuntimeDeps by setting suffix-path = false in your packageDefinitions, which will cause it to prefix by default instead of suffix, or you can set it on a per-item basis by putting a set like this into a list in lspsAndRuntimeDeps instead { value = tailwindcss-language-server; pre = true; }

If this works, you should make sure you aren't installing a version of tailwindcss-language-server somewhere else that is not compatible with the project for some reason.

@BirdeeHub
Copy link
Owner

BirdeeHub commented Apr 25, 2025

but you say its ALL lsps, with a blank devenv shell?

That is definitely odd. Because in that case, devenv shouldnt be installing anything that overrides the one from nixCats?

I dont know of any reason why nixCats would work any differently inside a devenv shell? NixCats is a simple wrapper script, it literally just adds stuff to the environment before launching nvim. I dont know why that would work differently inside a devenv shell.

I dont use devenv much, I only really use it when I load other peoples projects that do. I havent noticed this, but I will check it out again and see if I can reproduce this.

For what its worth, it seems to behave appropriately in a normal dev shell.

But yeah please let me know if changing it to prefix the path solves the issue.

@BirdeeHub
Copy link
Owner

BirdeeHub commented Apr 25, 2025

Ok. I ran nix shell nixpkgs#devenv

ran devenv init in a blank directory

Then I did devenv shell

All my nixCats provided lsps work still inside the shell (without doing prefix)

I tested nix rust lua go and bash lsps inside the shell, they all worked.

So it doesnt happen in a blank devenv shell for me?

I also tried enabling languages.go in the devenv shell and that seems to not break things?

So hopefully setting it to prefix those lsps to the path instead of suffix will fix things for you, as then in theory the one you should be running then would always be the one provided from nixCats because the wrapper script you launch nvim with prefixes the path with them on startup, rather than suffixing the path with them.

Its also possible the lsp requires a compiler of the matching version on the path, in which case installing it via the dev shell is often what you want, as otherwise you would need to also install the compiler via nixCats and prefix that as well so you can make sure they have the same version, which may not always match the one your project needs.

Rust can be like this sometimes. I have nixCats suffix the rust stuff in my config for when I have no shell and let the shell provide its own for the project which then overrides my one from nixCats, because installing a toolchain provides an lsp in rust by default, so its honestly easier to do that than to not do it.

@BirdeeHub
Copy link
Owner

BirdeeHub commented Apr 25, 2025

in particular, personally after trying --prefix vs --suffix to see if that fixes it, I would start my debug search by looking at what these provide. You may find that they are providing the lsps, but doing so in a way incompatible with your current lua lsp configuration, or that they dont provide the lsp, but they provide a compiler incompatble with your lsp provided via nixCats, and your lsp is failing trying to use it.

  languages = {
    erlang.enable = true;
    elixir.enable = true;
  };

from devenv's code

https://github.com/cachix/devenv/blob/36807c727e743e7a00999922e7f737a0cc4e05ac/src/modules/languages/elixir.nix#L1C1-L32C2

  config = lib.mkIf cfg.enable
    {
      git-hooks.hooks = {
        credo.package = cfg.package;
        dialyzer.package = cfg.package;
        mix-format.package = cfg.package;
        mix-test.package = cfg.package;
      };

      packages = with pkgs; [
        cfg.package
        elixir_ls
      ];
    };

Looks like they install elixir_ls

and also looks like they install erlang-ls

https://github.com/cachix/devenv/blob/36807c727e743e7a00999922e7f737a0cc4e05ac/src/modules/languages/erlang.nix#L1-L29

  config = lib.mkIf cfg.enable
    {
      packages = [
        cfg.package
        pkgs.erlang-ls
        rebar3
      ];
    };

So, your nixCats isnt working because those are being found instead and for some reason with your lua config that isnt ok?

Hopefully setting it to prefix them is all you need here, and if not hopefully this gives you the info needed to debug this and figure out what else needs to be included or what is going wrong :)

If you figure it out, please update us here and I can convert it to a discussion to help others with the same issue. If you don't figure it out we can of course continue to explore further.

@BirdeeHub BirdeeHub added question Further information is requested stale labels May 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested stale
Projects
None yet
Development

No branches or pull requests

2 participants