NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.63k stars 13.78k forks source link

Package request: tabnine-nvim #240176

Open opdavies opened 1 year ago

opdavies commented 1 year ago

Project description

Neovim plugin for code completion with Tabnine.

Metadata

vendion commented 6 months ago

I don't know if it is okay to bump requests like this, but I would love it if Tabnine (and the chat module) be added to nixpkgs.

janonymousm commented 4 months ago

Until a package is available, you can add it to your configuration yourself, but beware, my solution is somewhat ugly.

programs.neovim.plugins =
  with pkgs.vimPlugins;
  let
    tabnine-nvim = pkgs.vimUtils.buildVimPlugin {
      name = "tabnine-nvim";
      src = pkgs.fetchFromGitHub {
        owner = "codota";
        repo = "tabnine-nvim";
        rev = "a9baab62d29f1696f475ef3597e061f0920c9077";
        sha256 = "sha256-D0fKeppxM59NMNeXpGa5AfPcpbGMwGCZkM9IQ2NgcwY=";
      };
      buildInputs = [
        pkgs.tabnine
        pkgs.semver-lua
      ];
      buildPhase = ''
        patchShebangs .

        # Determine the Tabnine version and target platform
        version=${pkgs.tabnine.version}
        platform=${pkgs.tabnine.platform}

        # Create the expected directory structure
        mkdir -p binaries/$version/$platform
        cp ${pkgs.tabnine}/bin/* binaries/$version/$platform

        # Make the binaries executable
        chmod +x binaries/$version/$platform/*

        # Add semver.lua to the correct location
        cp ${pkgs.semver-lua}/semver.lua ./lua/tabnine/third_party/semver/
      '';
    };
  in
  [
    tabnine-nvim
  ];

_Note: I use Home Manager and you should likely use the latest version of the plugin. Also, the semver-lua package is an overlay, because I couldn't find it:

self: super:
let
  version = "1.2.1";
in
{
  semver-lua = super.pkgs.stdenv.mkDerivation {
    pname = "semver-lua";
    version = "v${version}";

    src = super.fetchFromGitHub {
      owner = "kikito";
      repo = "semver.lua";
      rev = "v${version}";
      hash = "sha256-S0Rn6/FR/Dt+GtHZtEv1Ad1/6B4Abep6IBot887BRuc=";
    };
    installPhase = ''
      runHook preInstall
      install -Dm755 semver.lua $out/semver.lua
      runHook postInstall
    '';
  };
}