How to custom package vim plugin on nixos?

Hi,

TL;DR: I want to make a custom package for vim plugin NeoDebug to use with my vim-with-plugins.nix located in /etc/nixos/ and i don’t use Home Manager (yet). Don’t mind if it is system wide for now. Also i am complete nix noob (only two weeks on Nixos). Thanks for any help!

My End goal: package NeoDebug plugin (NeoDebug) and use it with my vim-with-plugins.

I have this example: from here

{ config, pkgs, ... }:

let
  easygrep = pkgs.vimUtils.buildVimPlugin {
    name = "vim-easygrep";
    src = pkgs.fetchFromGitHub {
      owner = "dkprice";
      repo = "vim-easygrep";
      rev = "d0c36a77cc63c22648e792796b1815b44164653a";
      hash = "sha256-bL33/S+caNmEYGcMLNCanFZyEYUOUmSsedCVBn4tV3g=";
    };
  };
in
{
  environment.systemPackages = [
    (
      pkgs.neovim.override {
        configure = {
          packages.myPlugins = with pkgs.vimPlugins; {
          start = [
            vim-go # already packaged plugin
            easygrep # custom package
          ];
          opt = [];
        };
        # ...
      };
     }
    )
  ];
}

and also this:

    

    visual-star = pkgs.vimUtils.buildVimPlugin {
      name = "visual-star";
      src = pkgs.fetchFromGitHub {
        owner = "bronson";
        repo = "vim-visual-star-search";
        rev = "master";
        sha256 = "1fmfsalmj5qam439rv5wm11az53ql9h5ikg0drx3kp8d5b6fcr9c";
      };
    };


  

But where do i paste this type of code? I just heard of Home-Manager but i haven’t used it yet. Currently i have a “vim-with-plugins.nix” in /etc/nixos/ with the following:

{ pkgs, ... }:
{
  environment.variables = { EDITOR = "vim"; };
 
  environment.systemPackages = with pkgs; [
    ((vim-full.override {  }).customize{
      name = "vim-with-plugins";
      # Install plugins for example for syntax highlighting of nix files
      vimrcConfig.packages.myplugins = with pkgs.vimPlugins; {
        start = [ lightline-vim fzfWrapper vim-visual-multi vim-surround nerdtree coc-nvim auto-pairs gruvbox vim-cmake ];
        opt = [];
      };
      vimrcConfig.customRC = ''
        set laststatus=2
        set nocompatible
        set backspace=indent,eol,start
        syntax on
        set nu
        set termguicolors
        colo gruvbox

        inoremap <c-b> <Esc>:NERDTreeToggle<cr>
        nnoremap <c-b> <Esc>:NERDTreeToggle<cr>

        " use <tab> to trigger completion and navigate to the next complete item
        function! CheckBackspace() abort
        let col = col('.') - 1
        return !col || getline('.')[col - 1]  =~# '\s'
        endfunction

        inoremap <silent><expr> <Tab>
              \ coc#pum#visible() ? coc#pum#next(1) :
              \ CheckBackspace() ? "\<Tab>" :
              \ coc#refresh()
      '';
    }
  )];
}

and i just import that in my configuration.nix:

  imports =
    [ # Include the results of the hardware scan.
      ./hardware-configuration.nix
      ./vim-with-plugins.nix
    ];

I tried pasting the vim-easygrep example in configuration.nix and vim-with-plugins.nix to make a custom vim plugin package but i get errors when rebuilding. I feel like it’s just a small piece of the puzzle that i am missing.

Thanks.

Should be something like this:

# ./vim-with-plugins.nix
{ pkgs, ... }:

let
  NeoDebug = pkgs.vimUtils.buildVimPlugin {
    name = "vim-NeoDebug";
    src = pkgs.fetchFromGitHub {
      owner = "cpiger";
      repo = "NeoDebug";
      rev = "545d32f75dff49de5bf1d13022057eeb9ba5582d";
      hash = "";
    };
  };
in
{
  environment.variables = { EDITOR = "vim"; };
 
  environment.systemPackages = with pkgs; [
    ((vim-full.override {  }).customize{
      name = "vim-with-plugins";
      # Install plugins for example for syntax highlighting of nix files
      vimrcConfig.packages.myplugins = with pkgs.vimPlugins; {
        start = [ 
          lightline-vim 
          fzfWrapper 
          vim-visual-multi 
          vim-surround 
          nerdtree 
          coc-nvim 
          auto-pairs 
          gruvbox 
          vim-cmake 
          NeoDebug
        ];
        opt = [];
      };
      vimrcConfig.customRC = ''
        <removed for brevity>
      '';
    }
  )];
}

You’ll need to fill in the hash, just try to build it and read the error message.

2 Likes