nixvim icon indicating copy to clipboard operation
nixvim copied to clipboard

[HELP] nixd not working

Open jukremer opened this issue 1 year ago • 4 comments

Field Description
Plugin lsp
Nixpkgs unstable
Home Manager unstable

  • [x] I have read the FAQ and my bug is not listed there.

Description

I switched my Nix LSP from nil to nixd but it doesn't work. What am I doing wrong?

Here is my lsp.log:

[START][2024-09-21 20:48:05] LSP logging initiated
[ERROR][2024-09-21 20:48:05] .../vim/lsp/rpc.lua:0	"rpc"	"/nix/store/ak5sq7qm415010g9f7l51h1921fi1c7b-nixd-2.3.2/bin/nixd"	"stderr"	"I["
[ERROR][2024-09-21 20:48:05] .../vim/lsp/rpc.lua:0	"rpc"	"/nix/store/ak5sq7qm415010g9f7l51h1921fi1c7b-nixd-2.3.2/bin/nixd"	"stderr"	"20:48:05.341] 72730: <-- initialize"
[ERROR][2024-09-21 20:48:05] .../vim/lsp/rpc.lua:0	"rpc"	"/nix/store/ak5sq7qm415010g9f7l51h1921fi1c7b-nixd-2.3.2/bin/nixd"	"stderr"	"(1)\nI"
[ERROR][2024-09-21 20:48:05] .../vim/lsp/rpc.lua:0	"rpc"	"/nix/store/ak5sq7qm415010g9f7l51h1921fi1c7b-nixd-2.3.2/bin/nixd"	"stderr"	"[20:48:05.341] 72730: --> reply:initialize(1)\n"
[ERROR][2024-09-21 20:48:05] .../vim/lsp/rpc.lua:0	"rpc"	"/nix/store/ak5sq7qm415010g9f7l51h1921fi1c7b-nixd-2.3.2/bin/nixd"	"stderr"	"I[20:48:05.341] 72730: --> call window/workDoneProgress/create(1)\nI[20:48:05.341] 72730: --> notify $/progress\nI[20:48:05.341] 72730: --> call attrset/evalExpr(1)\nI[20:48:05.342] 72730: --> call window/workDoneProgress/create(2)\nI[20:48:05.342] 72730: --> notify $/progress\nI[20:48:05.342] 72730: --> call attrset/evalExpr(1)\nI[20:48:05.342] 72730: --> call workspace/configuration(3)\nI[20:48:05.342] 72730: <-- initialized\nI[20:48:05.342] 72730: <-- workspace/didChangeConfiguration\nI[20:48:05.342] 72730: --> call workspace/configuration(4)\nI[20:48:05.342] 72730: <-- textDocument/didOpen\n"
[ERROR][2024-09-21 20:48:05] .../vim/lsp/rpc.lua:0	"rpc"	"/nix/store/ak5sq7qm415010g9f7l51h1921fi1c7b-nixd-2.3.2/bin/nixd"	"stderr"	"I[20:48:05.342] 72730: --> notify textDocument/publishDiagnostics\nI[20:48:05.342] 72730: <-- textDocument/documentColor(2)\n"
[ERROR][2024-09-21 20:48:05] .../vim/lsp/rpc.lua:0	"rpc"	"/nix/store/ak5sq7qm415010g9f7l51h1921fi1c7b-nixd-2.3.2/bin/nixd"	"stderr"	"I[20:48:05.342] 72730: --> notify exit\n"
[ERROR][2024-09-21 20:48:05] .../vim/lsp/rpc.lua:0	"rpc"	"/nix/store/ak5sq7qm415010g9f7l51h1921fi1c7b-nixd-2.3.2/bin/nixd"	"stderr"	"I[20:48:05.575] 72730: <-- reply(1)\n"
[ERROR][2024-09-21 20:48:05] .../vim/lsp/rpc.lua:0	"rpc"	"/nix/store/ak5sq7qm415010g9f7l51h1921fi1c7b-nixd-2.3.2/bin/nixd"	"stderr"	"I[20:48:05.575] 72730: --> notify \n

Minimal, Reproducible Example (MRE)

programs.nixvim = {
plugins = {
  lsp = {
    enable = true;
      servers = {
         nixd.enable = true;
      };
   };
};
}

jukremer avatar Sep 21 '24 18:09 jukremer

@khaneliman Did some research and found this in your config:

https://github.com/khaneliman/khanelivim/commit/e6756ec54cb58857d24b55b83c13ec994764cc53

Does nixd not work atm?

jukremer avatar Sep 22 '24 06:09 jukremer

@khaneliman Did some research and found this in your config:

https://github.com/khaneliman/khanelivim/commit/e6756ec54cb58857d24b55b83c13ec994764cc53

Does nixd not work atm?

Was trying it out to see if I could replicate. I am getting the current crashes too and trying to see if there's something we can do to fix it or if it's an upstream package issue

khaneliman avatar Sep 22 '24 08:09 khaneliman

I've been using nixd for a while and haven't noticed any major issues. Sometimes I do need to restart nvim or the LSP though, so that is likely caused by intermittent nixd crashing.

MattSturgeon avatar Sep 22 '24 17:09 MattSturgeon

Is there any update on this?

I am following vimjoyers video https://youtu.be/M_zMoHlbZBY and hoping the nixd lsp will provide autocompletion for the all nixvim packages. e.g. when typing programs.nixvim.plugins.tm.... it will complete with tmux-navigator. Is this the correct expectation when using nixd with nixvim nixosModule flake input?

mairs8 avatar Oct 24 '24 20:10 mairs8

I am following vimjoyers video https://youtu.be/M_zMoHlbZBY and hoping the nixd lsp will provide autocompletion for the all nixvim packages. e.g. when typing programs.nixvim.plugins.tm.... it will complete with tmux-navigator. Is this the correct expectation when using nixd with nixvim nixosModule flake input?

I'm trying to achieve the same, but you can't get nixvim autcompletions with the setup of vimjoyer (it's not an actual bug/problem of nixd or nixvim) because you have to add an additional nixvim.expr, e.g.

nixd = {
  enable = true;
  settings = {
    formatting.command = [ "nixfmt" ];
    nixpkgs.expr = "import <nixpkgs> { }";

    options =
      let
        flake = "(builtins.getFlake \"/PATH/TO/FLAKE)\"";
      in
      {
        # Completitions for nixos and home manager options
        nixos.expr = "${flake}.nixosConfigurations.CONFIGNAME.options";
        home_manager.expr = "${flake}.homeConfigurations.CONFIGNAME.options";

        # nixvim.expr = "(builtins.getFlake \"github:nix-community/nixvim\").*don't know what to put here*.options";
      };
  };
};

cooparo avatar Oct 29 '24 13:10 cooparo

nixvim.expr = "(builtins.getFlake \"github:nix-community/nixvim\").*don't know what to put here*.options"

What to put there depends on how you have installed nixvim.

If you have a standalone nixvim, you can use .options on the nixvim derivation (package):

${flake}.packages.${pkgs.stdenv.hostPlatform.system}.PKG_NAME.options

If you have a home-manager/nixos installation, you can use type.getSubOptions [] on the programs.nixvim option:

${flake}.homeConfigurations.CONFIGNAME.options.programs.nixvim.type.getSubOptions []

Similar for nixos/darwin.

For a real world example, here's my nixd config and here's @traxys nixd config.

MattSturgeon avatar Oct 29 '24 19:10 MattSturgeon

I don't get it. I have nixvim in my flake's input and installed through home-manager. Actually this is my config and this is my nixd setup.

So I've tried the second method you mentioned, if I do

nix-repl> flake.homeConfigurations.paro.options.programs.nixvim
{
  __toString = «lambda __toString @ /nix/store/wb6agba4kfsxpbnb5hzlq58vkjzvbsk6-source/lib/modules.nix:823:22»;
  _type = "option";
  declarationPositions = [ ... ];
  declarations = [ ... ];
  default = { ... };
  definitions = [ ... ];
  definitionsWithLocations = [ ... ];
  files = [ ... ];
  highestPrio = 100;
  isDefined = true;
  loc = [ ... ];
  options = [ ... ];
  type = { ... };
  value = { ... };
}

I get this, where flake = builtins.getFlake /PATH/TO/FLAKE, but if I add getSubOptions [] I get an error error: attribute 'getSubOptions' missing, It is supposed to fail with nix repl or I'm missing something?

cooparo avatar Oct 29 '24 20:10 cooparo

My mistake, I was typing mostly from memory.

It should be <option>.type.getSubOptions [].

I'll edit above and mark these comments resolved.

MattSturgeon avatar Oct 29 '24 21:10 MattSturgeon

confirmed this works for me with

nixvim.expr = "(builtins.getFlake \"/home/USER/.dotfiles/NixOS-01\").nixosConfigurations.system.options.programs.nixvim.type.getSubOptions []";

mairs8 avatar Oct 30 '24 08:10 mairs8

We have https://github.com/nix-community/nixvim/issues/2390 to track a very specific nixd issue, but otherwise things seem to be working. Therefore I'll close this for now.

Feel free to keep commenting if you have more to add, or maybe open Q+A "discussions" if that's more appropriate.

MattSturgeon avatar Oct 30 '24 23:10 MattSturgeon

I'm still having this issue.

I updated my config and tested it in Helix where it works perfectly.

nixd = {
  enable = true;
  settings = {
    formatting.command = [ "nixfmt" ];
    nixpkgs.expr = "import (builtins.getFlake \"~/.config/nix\").inputs.nixpkgs { }";
    options = {
      nixos.expr = "(builtins.getFlake \"~/.config/nix\").nixosConfigurations.galanthus.options";
      darwin.expr = "(builtins.getFlake \"~/.config/nix\").darwinConfigurations.malus.options";
      home-manager.expr = "(builtins.getFlake \"~/.config/nix\").homeConfigurations.jan.options";
    };
  };
};
[START][2024-11-09 15:10:42] LSP logging initiated
[ERROR][2024-11-09 15:10:42] .../vim/lsp/rpc.lua:0	"rpc"	"/nix/store/wmlfl6vi9c3sgq5dcycf4giss7ys8ng8-nixd-2.4.0/bin/nixd"	"stderr"	"I["
[ERROR][2024-11-09 15:10:42] .../vim/lsp/rpc.lua:0	"rpc"	"/nix/store/wmlfl6vi9c3sgq5dcycf4giss7ys8ng8-nixd-2.4.0/bin/nixd"	"stderr"	"15:10:42.543] "
[ERROR][2024-11-09 15:10:42] .../vim/lsp/rpc.lua:0	"rpc"	"/nix/store/wmlfl6vi9c3sgq5dcycf4giss7ys8ng8-nixd-2.4.0/bin/nixd"	"stderr"	"40219: <-- initialize(1)\n"
[ERROR][2024-11-09 15:10:42] .../vim/lsp/rpc.lua:0	"rpc"	"/nix/store/wmlfl6vi9c3sgq5dcycf4giss7ys8ng8-nixd-2.4.0/bin/nixd"	"stderr"	"I[15:10:42.543] 40219: --> reply:initialize(1)\n"
[ERROR][2024-11-09 15:10:42] .../vim/lsp/rpc.lua:0	"rpc"	"/nix/store/wmlfl6vi9c3sgq5dcycf4giss7ys8ng8-nixd-2.4.0/bin/nixd"	"stderr"	"I[15:10:42.543] 40219: --> call window/workDoneProgress/create(1)\nI[15:10:42.543] 40219: --> notify $/progress\nI[15:10:42.543] 40219: --> call attrset/evalExpr(1)\nI[15:10:42.544] 40219: --> call window/workDoneProgress/create(2)\nI[15:10:42.544] 40219: --> notify $/progress\nI[15:10:42.544] 40219: --> call attrset/evalExpr(1)\nI[15:10:42.544] 40219: --> call workspace/configuration(3)\nI[15:10:42.544] 40219: <-- initialized\nI[15:10:42.544] 40219: <-- workspace/didChangeConfiguration\nI[15:10:42.544] 40219: --> call workspace/configuration(4)\nI[15:10:42.544] 40219: <-- textDocument/didOpen\nI[15:10:42.544] 40219: --> notify textDocument/publishDiagnostics\nI[15:10:42.544] 40219: <-- textDocument/documentColor(2)\n"
[ERROR][2024-11-09 15:10:42] .../vim/lsp/rpc.lua:0	"rpc"	"/nix/store/wmlfl6vi9c3sgq5dcycf4giss7ys8ng8-nixd-2.4.0/bin/nixd"	"stderr"	"I[15:10:42.544] 40219: --> notify exit\n"
[ERROR][2024-11-09 15:10:42] .../vim/lsp/rpc.lua:0	"rpc"	"/nix/store/wmlfl6vi9c3sgq5dcycf4giss7ys8ng8-nixd-2.4.0/bin/nixd"	"stderr"	"I[15:10:42.878] 40219: <-- reply(1)"
[ERROR][2024-11-09 15:10:42] .../vim/lsp/rpc.lua:0	"rpc"	"/nix/store/wmlfl6vi9c3sgq5dcycf4giss7ys8ng8-nixd-2.4.0/bin/nixd"	"stderr"	"\nI[15:10:42.878] 40219: --> notify \n"

jukremer avatar Nov 09 '24 14:11 jukremer

We have #2390 to track a very specific nixd issue, but otherwise things seem to be working. Therefore I'll close this for now.

Feel free to keep commenting if you have more to add, or maybe open Q+A "discussions" if that's more appropriate.

the above solution i had stopped working, not sure why. it seems to be quite a temperamental piece of config that i see people struggle with on different forums

mairs8 avatar Nov 21 '25 20:11 mairs8