NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.98k stars 14k forks source link

onedark-vim: Error detected while processing package #96062

Closed mjlbach closed 3 years ago

mjlbach commented 4 years ago

Describe the bug For some reason, onedark.vim is failing to load.

Error detected while processing /nix/store/462h5wxl2g88nyj5mck4x85fqfhf79i7-vim
plugin-onedark-vim-2020-08-12/share/vim-plugins/onedark-vim/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:

To Reproduce Steps to reproduce the behavior (if using home-manager)

programs.neovim = {
      enable = true;
      configure = {
      customRC = ''
         colorscheme onedark
        '';
      packages.myVimPackage = with pkgs.vimPlugins; {
        start = [
            onedark-vim

          ];
        };
    };
  };

or

  programs.neovim = {
      enable = true;
      extraConfig = ''
         colorscheme onedark
        '';
      plugins = with pkgs.vimPlugins; [
            onedark-vim
          ];
    };

if the customRC attribute is left out, onedark-vim loads fine if invoked manually after neovim start.

Furthermore, this can be fixed by ammending the rtp: The following amendment to rtp fixes it:

{ config, pkgs, libs, ... }:

let 

    loadPlugin = plugin: ''
      set rtp^=${plugin.rtp}
      set rtp+=${plugin.rtp}/after
    '';
    plugins = with pkgs.vimPlugins; [
          onedark-vim
        ];
in
{
  home.packages = with pkgs;  with stdenv.lib; [
    # neovim
    rnix-lsp
  ] ++ optionals stdenv.isLinux [ python-language-server ] ;
  # xdg.configFile."nvim/init.vim".source = ../configs/neovim/init.vim;
  programs.neovim = {
      enable = true;
      extraConfig = ''
            " Workaround for broken handling of packpath by vim8/neovim for ftplugins -- see https://github.com/NixOS/nixpkgs/issues/39364#issuecomment-425536054 for more info
            filetype off | syn off
            ${builtins.concatStringsSep "\n"
            (map loadPlugin plugins)}
            filetype indent plugin on | syn on
            colorscheme onedark
        '';
    };
}

Metadata ❯ nix-shell -p nix-info --run "nix-info -m" these paths will be fetched (0.00 MiB download, 0.00 MiB unpacked): /nix/store/1hg7ssk7dzpmccsz018p8vb9jr3pq47i-nix-info copying path '/nix/store/1hg7ssk7dzpmccsz018p8vb9jr3pq47i-nix-info' from 'https://cache.nixos.org'...

This seems like it's related to: https://github.com/NixOS/nixpkgs/issues/39364 https://github.com/NixOS/nixpkgs/pull/78385

jonringer commented 4 years ago

really wish we didn't have like 3 different conventions in how to configure vim. Makes it really confusing as to which one is preferred.

megheaiulian commented 4 years ago

The home-manager's neovim configuration is separate from nixpkgs/nixos as you can see at https://github.com/rycee/home-manager/blob/master/modules/programs/neovim.nix. Nixos/nixpkgs does not have a programs.neovim option ?

mjlbach commented 4 years ago

Home-manager uses the same infrastructure for neovim/vim plugin management as nix, the issue can be reproduced without home-manager using the following nix-shell:

{ pkgs ? import <nixpkgs> { } }:
let
  neovim = pkgs.neovim.override {
    configure = {
      customRC = ''
        colorscheme onedark
      '';
      packages.myVimPackage = with pkgs.vimPlugins; {
        # see examples below how to use custom packages
        start = [ onedark-vim ];
      };
    };
  };
in
pkgs.mkShell {
  buildInputs = [ neovim ];
}
basilgood commented 4 years ago

Onedark color scheme has installation instructions for vim8 package manager: https://github.com/joshdick/onedark.vim#installation

{ pkgs ? import <nixpkgs> { } }:
let
  neovim = pkgs.neovim.override {
    configure = {
      customRC = ''
        packadd! onedark-vim
        colorscheme onedark
      '';
      packages.myVimPackage = with pkgs.vimPlugins; {
        # see examples below how to use custom packages
        opt = [ onedark-vim ];
      };
    };
  };
in
pkgs.mkShell {
  buildInputs = [ neovim ];
}

It's not a nixpkgs problem.

mjlbach commented 4 years ago

@basilgood That works. Is this the intended behavior of vim packages in nixpkgs? It seems odd that some modules work without manually activating them with packadd! and some do not (nvim-lsp, onedark-vim)

basilgood commented 4 years ago

@mjlbach It's a vim8 native package manager behavior. Nixpkgs follows the same behavior. In this case (onedark.vim) it's a colorscheme plugin and they probably didn't expect from a colorscheme plugin to contain an autoload folder and so autoload it's not loaded. Same thing with dracula colorscheme and probably with some other plugins which does not follow vim8 pack rules. But nvim-lsp in my experience works out of the box either in start or opt.

rpearce commented 3 years ago

This was really helpful. Thanks for the packadd! onedark-vim bit!

megheaiulian commented 3 years ago

I think this can be closed as the vim/neovim configuration works as expected.