Home-manager: Should neovim expose an extraPackages?

Created on 29 Oct 2019  Â·  6Comments  Â·  Source: nix-community/home-manager

Currently programs.neovim exposes extraPythonPackages and the Python 3 analogue. There are, however, non-python packages that it would be interesting to make available/visible from Neovim, such as Yarn and Node for coc-vim, or any number of formatters for vim-ale.

Should we expose this next to current Python options?

Most helpful comment

The neovim wrapper also offers extraMakeWrapperArgs. I'm using them like this in my overlay

```.nix
{
wrapNeovim = nvim: args: super.wrapNeovim nvim (
if args ? "extraPackages"
then super.lib.filterAttrs (n: v: n != "extraPackages") args // {
extraMakeWrapperArgs = (args.extraMakeWrapperArgs or "")
+ " --prefix PATH : '${super.lib.makeBinPath args.extraPackages}'";
}
else args
);
}

and adding args to `makeWrapper` is the way this would be implemented in nixpkgs.

Maybe it would be more pleasant to add this to the wrapper in nixpkgs, but until then, in home-manager one could add

```.nix
extraMakeWrapperArgs = "--prefix PATH : '${lib.makeBinPath cfg.extraPackages}'";

to the call of wrapNeovim.

All 6 comments

Seems the neovim wrapper only offers extraPythonPackages and extraPython3Packages:
https://github.com/NixOS/nixpkgs/blob/d3248c915ed04b78734ff1bfc11f0644c4531941/pkgs/applications/editors/neovim/wrapper.nix#L14-L23
I'm afraid that if HM is to support additional options along these lines support for them would first have to be added to the wrapper.

The neovim wrapper also offers extraMakeWrapperArgs. I'm using them like this in my overlay

```.nix
{
wrapNeovim = nvim: args: super.wrapNeovim nvim (
if args ? "extraPackages"
then super.lib.filterAttrs (n: v: n != "extraPackages") args // {
extraMakeWrapperArgs = (args.extraMakeWrapperArgs or "")
+ " --prefix PATH : '${super.lib.makeBinPath args.extraPackages}'";
}
else args
);
}

and adding args to `makeWrapper` is the way this would be implemented in nixpkgs.

Maybe it would be more pleasant to add this to the wrapper in nixpkgs, but until then, in home-manager one could add

```.nix
extraMakeWrapperArgs = "--prefix PATH : '${lib.makeBinPath cfg.extraPackages}'";

to the call of wrapNeovim.

@jorsn I've recently found your solution, but I'm new to Nix and home-manager, and I wasn't able to make it work.

Could you explain it in greater detail?

I've partially understood the overlay part (even if I'm not sure on how to integrate it with my neovim-unwrapped-nightly overlay) but I keep getting errors from home-manager because it doesn't recognize extraMakeWrapperArgs as an attribute for neovim.

@biosan
The neovim wrapper linked in rycee's post above is assigned to the attribute name wrapNeovim in nixpkgs.
It expects two arguments: nvim :: derivation (the unwrapped neovim) and args :: attrset.

The snipped above placed in an overlay overrides this function. It passes the nvim argument directly to the underlying super.wrapNeovim and modifies the args: If they contain an attr extraPackages, then this is filtered out (edit!) because super.wrapNeovim doesn't accept it as argument and its value translated to the right extraMakeWrapperArgs, which super.wrapNeovim in turn passes to the shell function makeWrapper. The latter wraps nvim with the right environment so that it finds all the binaries and libraries it needs (e.g. python libs, see the source wrapper.nix linked above by rycee).

All that should be required to use my snippet is adding an overlay to your nixpkgs/home-manager config, like

{ nixpkgs.overlays = (self: super: {
    wrapNeovim = nvim: args: super.wrapNeovim nvim (
      if args ? "extraPackages"
      then super.lib.filterAttrs (n: v: n != "extraPackages") args // {
        extraMakeWrapperArgs = (args.extraMakeWrapperArgs or "")
          + " --prefix PATH : '${super.lib.makeBinPath args.extraPackages}'";
      }
      else args
    );
  });

  programs.neovim = {
    package = pkgs.neovim-unwrapped;
    …
  };
}

if pkgs.neovim-unwrapped is your nightly neovim.

According to a quick look at <nixpkgs/pkgs/top-level/all-packages.nix>,
the package neovim should use the redefined wrapNeovim automatically. But if
it does not, you have can override it in an overlay like this:

self: super:
{
  neovim = wrapNeovim self.neovim-unwrapped {};
}

Does this work for you? Otherwise I have to look whether the order of something plays a role, but this would be tomorrow or later.

Thank you very much @jorsn for the quick (and very complete) response, I learned a lot and I'm very sorry for the late reply.
But it's still unclear to me how to set the extra packages in my home.nix file.
I'm probably missing something very simple, as a said before I'm very new to Nix and home-manager.

No problem @biosan!
Did you try copying my above snippet (without the …)? Did you get errors?

Could you give an example (with code) of what you are trying to do? E.g. the relevant parts of your home.nix (or the complete file)? If we talk about your specific problem (and not about home-manager itself), maybe you open a thread on https://discourse.nixos.org and we discuss it there? If this results in something relevant to the development of home-manager, we can still post that back here.

Was this page helpful?
0 / 5 - 0 ratings