1

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.

Vey
  • 435
  • 5
  • 15
  • As it's run time dependency and not build time you might need to look into wrapping. See here: https://stackoverflow.com/a/69395418/1663462 – Chris Stryczynski Mar 23 '23 at 10:17

1 Answers1

3

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
  '';
kbmz
  • 83
  • 3
  • 1
    This works well. The `sed` invocation needs to be changed a little bit. I can't edit your post and I can't post code blocks as comments but the updated `sed` call is [here](https://www.reddit.com/r/NixOS/comments/11zfnu7/how_to_make_nodejs_available_on_path_to_vim_plugin/) – Vey Mar 23 '23 at 15:54