Exafunction / codeium.nvim

A native neovim extension for Codeium
MIT License
647 stars 50 forks source link

Usage with nix #18

Closed DieracDelta closed 1 year ago

DieracDelta commented 1 year ago

Cool project! Is there an example usage of setting this up with nix I can base my config on? (maybe a personal flake or something)

jcdickinson commented 1 year ago

Sure.

  1. I generate a lua file containing any packages that I use in my nvim config: https://gitlab.com/jcdickinson/nix/-/blob/main/home/nvim.nix#L16 2.1. That does include a bare-bones FHS wrapper for my nixos machine: https://gitlab.com/jcdickinson/nix/-/blob/main/home/nvim.nix#L70
  2. I have a utility function that requires that file and grabs the package path out of it: https://gitlab.com/jcdickinson/nix/-/blob/main/home/files/nvim/lua/jcdickinson/util.lua#L88
  3. I hook that up as the wrapper function (as well as curl and gzip): https://gitlab.com/jcdickinson/nix/-/blob/main/home/files/nvim/lua/plugins/codeium.lua#L25
DieracDelta commented 1 year ago

Thanks for the response, this is super helpful!

I'm trying to generate everything at compile(build?) time using nix sort like this. Is there an option to pass in the path to the wrapped binary during setup? I'm hoping I can build a derivation that fetches the binary and fhs wrap it (or auto-patchelf it if possible; I'm hoping to run this on a mac too), and pass the path to that into my generated lua config file.

jcdickinson commented 1 year ago

I pushed an update for this. You can set language_server under the tools to declare an explicit path.

DieracDelta commented 1 year ago

Thanks so much!! For others trying on nix, this is working for me now.

trevorfoxsoft commented 1 year ago

I'm pretty new to NixOS, still learning how Flakes work etc. I'd really like to get Codeium working via this plugin however, but I'm struggling. Would it be possible to provide a kind of "minimum viable setup" example?

My current setup is in a repo here, with the home-manager config here and Neovim here. Any pointers would be really gratefully received!

DieracDelta commented 1 year ago

Bring in codium as a dependency:

codium-nvim-src = {
  url = "github:jcdickinson/codeium.nvim";
  flake = false;
};

Create the derivation for the lsp:

  codium-lsp = with prev;
    stdenv.mkDerivation rec {
      pname = "codium-lsp";
      version = "v1.1.33";

      src = fetchurl {
        url = "https://github.com/Exafunction/codeium/releases/download/language-server-v1.1.33/language_server_macos_arm.gz";
        sha256 = "sha256-NYf0hSNO6bmICBFjpnzOvuKRBqPG7ijhdfbO02iOTBI=";
      };

      nativeBuildInputs = [
        # autoPatchelfHook
      ];

      buildInputs = [
      ];

      phases = [ "installPhase" ];

      # sourceRoot = ".";

      installPhase = ''
        mkdir -p $out/bin
        gzip -d $src -c > $out/bin/language_server
        chmod +x $out/bin/language_server
      '';

    }
  ;

Create the vim plugin:

let
  withSrc = pkg: src: pkg.overrideAttrs (_: { inherit src; });
  plugin = pname: src: prev.vimUtils.buildVimPluginFrom2Nix {
    inherit pname src;
    version = "master";
  };
in
codium-nvim = plugin "codium-nvim" codium-nvim-src;

You want both of the above in an overlay you apply when you import nixpkgs. Then list codium-nvim in your plugins list and then in your init.lua call:

require("codeium").setup({
  tools = { language_server = "{pkgs.codium-lsp}/bin/language_server"
  }
})
jcdickinson commented 1 year ago

I have made the flake.nix in this repo actually useful. It will deal with the server for you. You can use it with (updated with tested example :P):

{
  inputs = {
    nixpkgs.url = "nixpkgs/nixos-22.11";
    flake-utils.url = "github:numtide/flake-utils";
    codeium = {
      url = "github:jcdickinson/codeium.nvim";
      inputs.nixpkgs.follows = "nixpkgs";
    };
  };
  outputs = {
    nixpkgs,
    flake-utils,
    codeium,
    ...
  }
  :
    flake-utils.lib.eachDefaultSystem (
      system: let
        overlays = [codeium.overlays.${system}.default];
        pkgs = import nixpkgs {
          inherit system overlays;
        };
      in {
        formatter = pkgs.alejandra;

        packages = with pkgs; {
          nvimWithCodeium = neovim.override {
            configure = {
              customRC = ''
                lua require("codeium").setup()
              '';
              packages.myPlugins = {
                start = [vimPlugins.codeium-nvim vimPlugins.plenary-nvim vimPlugins.nvim-cmp];
              };
            };
          };
        };

        devShell = pkgs.mkShell {
          packages = [];
        };
      }
    );
}
trevorfoxsoft commented 1 year ago

Thank you for this! All working now. Hugely appreciated.