Search code examples
nixnixosnixpkgs

Custom Nix derivation for vim plugin fails


EDIT: leaving this as some history for other searching similar problems Some of it is solved, but last questions still unresolved See after the ==== line.

I am using home manager and I set it up to provide me with neovim including some plugins. Unfortunately the coc-nvim plugin is no longer up to date so now I would like to package it from github and then import. I am new to nixos so there are many things I still miss, I believe.

My naive approach so far is: .../neovim/default.nix

with import <nixpkgs> {};

let coc = callPackage ./coc-new.nix;
in
{
  enable = true;
  viAlias = true;
  vimAlias = true;
  withNodeJs = false;
  plugins = with pkgs.vimPlugins; [
    coc
    fzf-vim
    fzfWrapper
    haskell-vim
    some-more-plugins
  ];
  extraConfig = ''
    unlet! skip_defaults_vim
    " some more vimrc stuff
  '';
}

and then .../neovim/coc-new.nix

{ stdenv, fetchFromGithub, lib, config, options }:

stdenv.mkDerivation rec {
 name = "new-coc-${version}";
  version = "v0.80";

  src = fetchFromGithub {
    owner = "neoclide";
    repo = "coc.nvim";
    rev = "ce448a6945d90609bc5c063577e12b859de0834b";
#    sha256 = " ???";
  };

  installPhase = ''
    export PATH="''\${bash}/bin/bash"
    mkdir -p $out
    cp -r ./ $out
  '';
}

The error tells me that whatever is imported is not of some 'package' type:

error: The option `programs.neovim.plugins.[definition 1-entry 1].__ignoreNulls' defined in `/home/chai/.config/nixpkgs/role/laptop-old/index.nix' does not exist.

So please help me out:

  1. Am I correct that it is now defining a package but not actually building it ? And Hw do I go about fixing that?
  2. the values for rev : ... I set it to the commit hash found in coc repo on github, is that correct?
  3. the sha value.. where do I get that ?

Thanks for helping a new user on his way here!

==========================================================================

EDIT: With help of the comment and some reading up on man nix-has I managed to get the hashes and the build to work. I added the {} argument as suggested so in ...neovim/default.nix I now have

let coc = callPackage ./coc-new.nix {};

and .../neovim/coc-new.nix now reads:

{ stdenv, fetchFromGitHub }:

stdenv.mkDerivation rec {
  pname = "coc-nvim";
  version = "v0.80";

  src = fetchFromGitHub {
    owner = "neoclide";
    repo = "coc.nvim";
    rev = "v0.0.80";
    sha256 = "1c2spdx4jvv7j52f37lxk64m3rx7003whjnra3y1c7m2d7ljs6rb";
  };
  dontBuild = true;
  installPhase = ''
    mkdir -p $out
    cp -r ./ $out
  '';

}

It all runs but... the newly created derivation is not picked up. Nothing in my vim packs directory. Why ? I see in (home-manager/neovim.nix)[https://github.com/nix-community/home-manager/blob/master/modules/programs/neovim.nix] :


      plugins = mkOption {
        type = with types; listOf (either package pluginWithConfigType);
        default = [ ];
        example = literalExample ''
          with pkgs.vimPlugins; [
            yankring
            vim-nix
            { plugin = vim-startify;
              config = "let g:startify_change_to_vcs_root = 0";
            }
          ]
        '';

Solution

  • Ok I finally managed to get it working. After more searching and getting lost it turns out nix has pkgs.vimUtils.buildVimPlugin This solved my problem. My files now read:

    { pkgs, fetchFromGitHub }:
    
    pkgs.vimUtils.buildVimPlugin {
      pname = "coc-nvim";
      version = "v0.80";
    
      src = fetchFromGitHub {
        owner = "neoclide";
        repo = "coc.nvim";
        rev = "v0.0.80";
        sha256 = "1c2spdx4jvv7j52f37lxk64m3rx7003whjnra3y1c7m2d7ljs6rb";
      };
    }
    
    

    And ...

    with import <nixpkgs> {};
    let coc = callPackage ./coc-plugin.nix { };
    in
    {
      enable = true;
      viAlias = true;
      vimAlias = true;
      withNodeJs = false;
      plugins =  with pkgs.vimPlugins;[
        coc
        fzf-vim
        more-plugins
      ];
      extraConfig = ''
        unlet! skip_defaults_vim
        " ... more config
      '';
    }