Search code examples
nixgithub-copilotnixpkgs

How to make NodeJS available on PATH to Vim plugin?


I am trying to use the GitHub Copilot plugin for Neovim which is already available from Nixpkgs as copilot-vim. After installation, running the plugin with :Copilot setup gives me Copilot: 'Node.js not found in PATH'.

I thought I could just add NodeJS through an overlay, like this:

      (final: prev: {
        copilot-vim = prev.copilot-vim.overrideAttrs (old: {
          nativeBuildInputs = old.nativeBuildInputs ++ [prev.nodejs];
          buildInputs = old.buildInputs ++ [prev.nodejs];
        });
      })

But this doesn't make the error go away.

I know that I can just install NodeJS in whatever way. But my goal is to add NodeJS on PATH as a dependency to this plugin, rather than adding NodeJS in a decoupled fashion.


Solution

  • So, buildInputs only makes nodejs available during the build. But if the build output does not end up with a reference to nodejs, it won't be there in the finished package. Looking at the code to copilot-vim, it seems you would want to patch this line:

      let node = get(g:, 'copilot_node_command', '')
    

    to have your included node version as the default.

    I would probably do something like this:

      postInstall = ''
        sed -i "s!  let node = get(g:, 'copilot_node_command', ''\'''\')!  let node = get(g:, 'copilot_node_command', '${prev.nodejs}/bin/node')!g" $out/autoload/copilot/agent.vim
      '';