huggingface / llm-ls

LSP server leveraging LLMs for code completion (and more?)
Apache License 2.0
585 stars 46 forks source link

[BUG] Server doesn't start on NixOS #24

Open erkkimon opened 11 months ago

erkkimon commented 11 months ago

The plugin v0.1.0 installs fine on NixOS (23.05) and VSCodium v1.82.2.23257 but crashes on launch. This is the error that I get:

[Error - 2:52:13 PM] LLM VS Code client: couldn't create connection to server.
Launching server using command /home/erkkimon/.vscode-oss/extensions/huggingface.huggingface-vscode-0.1.0-linux-x64/server/llm-ls failed. Error: spawn /home/erkkimon/.vscode-oss/extensions/huggingface.huggingface-vscode-0.1.0-linux-x64/server/llm-ls ENOENT

Trying to run the server from terminal results error "No such file or directory", and the problem doesn't seem to be in execution rights:

# The file and containing folder exists
erkkimon@nixos:~/ > ls /home/erkkimon/.vscode-oss/extensions/huggingface.huggingface-vscode-0.1.0-linux-x64/server
llm-ls

# Calling the binary doesn't compute
erkkimon@nixos:~/ > /home/erkkimon/.vscode-oss/extensions/huggingface.huggingface-vscode-0.1.0-linux-x64/server/llm-ls 
zsh: no such file or directory: /home/erkkimon/.vscode-oss/extensions/huggingface.huggingface-vscode-0.1.0-linux-x64/server/llm-ls

# Making sure the binary is executable
erkkimon@nixos:~/ > chmod a+x /home/erkkimon/.vscode-oss/extensions/huggingface.huggingface-vscode-0.1.0-linux-x64/server/llm-ls

# Still no compute
erkkimon@nixos:~/ > /home/erkkimon/.vscode-oss/extensions/huggingface.huggingface-vscode-0.1.0-linux-x64/server/llm-ls          
zsh: no such file or directory: /home/erkkimon/.vscode-oss/extensions/huggingface.huggingface-vscode-0.1.0-linux-x64/server/llm-ls

Any ideas? If I figure out something, I will definitely let the internet know.

erkkimon commented 11 months ago

Just as an update, I talked with NixOS guys and the optimal NixOS way to do this would be building the server on NixOS and providing that endpoint to the extension.

So the steps would be the following:

  1. Create derivation (with help of nix-init if possible)
  2. Share the derivation on Github to others here as first-aid.
  3. Contribute the derivation to NixOS package management.

I will try to do this but if someone else accomplishes some of these steps, please share your results so we can play this game together!

McPatate commented 11 months ago

Check out how rust-analyzer solved this: https://github.com/rust-lang/rust-analyzer/blob/3b1b58c225d35414d90078dc7e06ca74a49cad0c/editors/code/src/bootstrap.ts.

If you think building a NixOS binary is the way to go, I'd add a step in the release CI to build it.

Thanks for digging into this!

erkkimon commented 11 months ago

Thanks @McPatate!

I managed to create a working derivation and at the moment I'm using llm-ls with llm-vscode on VSCodium running on NixOS. I have never submitted a derivation to nixpkgs but it will be my next battle to figure it out. I guess I'm already quite close.

Anyway, with this derivation it is possible to use llm-ls + VSCodium on NixOS with no problems before it will be available at nixpkgs. The derivation file (default.nix) looks like following:

{ pkgs ? import <nixpkgs> {} }:

let
  src = pkgs.fetchFromGitHub {
    owner = "huggingface";
    repo = "llm-ls";
    rev = "v0.2.1";
    sha256 = "1ja641l1sqzv3dczsf9ra99f3kz3cs07ha3m6vs9pj66x1lpbbvj";
  };
in
pkgs.rustPlatform.buildRustPackage rec {
  pname = "llm-ls";
  version = "0.2.1";
  inherit src;

  buildPhase = "cargo build --release";

  installPhase = ''
    mkdir -p $out/bin
    cp target/release/llm-ls $out/bin/llm-ls
  '';

  meta = {
    description = "llm-ls is a LSP server leveraging LLMs for code completion";
    homepage = "https://github.com/huggingface/llm-ls";
    license = pkgs.lib.licenses.asl20;
    maintainers = with pkgs.lib.maintainers; [ erkkimon ];
  };

  cargoSha256 = "JGCD8CXxbWwygVfpohM9yyFP/KGN604I4bSayg/gQzM=";
}

Building and usage:

  1. Create folder llm-ls somewhere you like, but in these instructions I assume /home/user/herpderp/llm-ls as the path.
  2. Create file called default.nix containing the derivation code above.
  3. Run nix-build.
  4. In VSCodium, hit CTRL + SHIFT + P and go to user settings (JSON).
  5. Add this line "llm.lsp.binaryPath": "/home/user/herpderp/llm-ls/result/bin/llm-ls" to the root level of the settings object.

NB! You can also add the llm-ls binary path through llm-vscode extension settings which will take you to the same settings JSON creating the right key with empty value, which you should replace with the path of the binary you just built using the derivation.