[HELP] nixd not working
| 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;
};
};
};
}
@khaneliman Did some research and found this in your config:
https://github.com/khaneliman/khanelivim/commit/e6756ec54cb58857d24b55b83c13ec994764cc53
Does nixd not work atm?
@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
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.
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?
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 withtmux-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";
};
};
};
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.
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?
My mistake, I was typing mostly from memory.
It should be <option>.type.getSubOptions [].
I'll edit above and mark these comments resolved.
confirmed this works for me with
nixvim.expr = "(builtins.getFlake \"/home/USER/.dotfiles/NixOS-01\").nixosConfigurations.system.options.programs.nixvim.type.getSubOptions []";
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.
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"
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