Home-manager: custom neovim plugins

Hello,

I’m getting started with home-manager and I’m trying to use the onedark colorscheme working. I have the following ~/.config/nixpkgs/home.nix:

{ config, pkgs, ... }:                                                      

let
customPlugins = {
    onedark = pkgs.vimUtils.buildVimPlugin {
        name = "onedark";
        src = pkgs.fetchgit {
            url = "https://github.com/joshdick/onedark.vim";
            rev = "5c74e9d1877e9ade09b8c9b65fc946958f2c979";
            sha256 = "03a2yq5ai5cwyxy6c24n738yf81wwnnchw3nicini0msr4nby2f2";
        };
        meta = {
            homepage = https://github.com/joshdick/onedark.vim;
            maintainers = [ "joshdick" ];
        };
    };
};
allPlugins = pkgs.vimPlugins // customPlugins;
in
{
  programs.home-manager.enable = true;
  home.stateVersion = "19.09";
  nixpkgs.config.allowUnfree = true;
  
  programs.neovim = {
      enable = true;
      vimAlias = true;
      viAlias = true;
      plugins = with allPlugins; [ onedark ];
      extraConfig = ''
          set background=dark
          colorscheme onedark
      '';
  };
}

This config builds correctly, but I have the colorscheme does not work:

% vim
Error detected while processing /nix/store/6kh8s3laq1ci21kriyqzzvmxd1dbjnx0-vimplugin-onedark/share/vim-plugins/onedark/colors/onedark.vim:
line  133:
E117: Unknown function: onedark#GetColors
E15: Invalid expression: onedark#GetColors()
line  135:
E121: Undefined variable: s:colors
E15: Invalid expression: s:colors.red
line  136:
E121: Undefined variable: s:colors
E15: Invalid expression: s:colors.dark_red
line  137:
E121: Undefined variable: s:colors
E15: Invalid expression: s:colors.green
line  138:
E121: Undefined variable: s:colors
E15: Invalid expression: s:colors.yellow
line  139:
E121: Undefined variable: s:colors
E15: Invalid expression: s:colors.dark_yellow
line  140:
E121: Undefined variable: s:colors
E15: Invalid expression: s:colors.blue
line  141:
E121: Undefined variable: s:colors
E15: Invalid expression: s:colors.purple
line  142:
E121: Undefined variable: s:colors
E15: Invalid expression: s:colors.cyan
line  143:
E121: Undefined variable: s:colors
E15: Invalid expression: s:colors.white
line  144:
E121: Undefined variable: s:colors
E15: Invalid expression: s:colors.black
line  145:
E121: Undefined variable: s:colors
E15: Invalid expression: s:colors.visual_black " Black out selected text in 16-color visual mode
...

This looks a lot like: https://github.com/joshdick/onedark.vim/issues/110
So I tried the fix suggested in the thread:

set background=dark
packadd! onedark.vim
colorscheme onedark

But this errors out:

% vim
Error detected while processing /nix/store/9jrlpmv4rqcrsswncz1bb2cbc2g3p09b-vimrc:
line   19:
E919: Directory not found in 'packpath': "pack/*/opt/onedark.vim"
Error detected while processing /nix/store/6kh8s3laq1ci21kriyqzzvmxd1dbjnx0-vimplugin-onedark/share/vim-plugins/onedark/colors/onedark.vim:
line  133:

Any idea what I am doing wrong here?

3 Likes