3 minutes
Neovim
Continuing learning Nix I wanted to move on real things before swallowing another pill.
So I decided to try and install nvim which is my main editor.
I’m using it with some plugins and configs that I wanted to move totally to Nix.
I found out that it’s not that easy to do (there is not so much docs on the topic).
I found 2 resources that helped me in the journey :
- https://www.mpscholten.de/nixos/2016/04/11/setting-up-vim-on-nixos.html
- https://nixos.wiki/wiki/Neovim
My goal was simply to configure neovim with nix while using the official derivation.
The first article helped me understand how to do it and the second showed me that neovim was pretty much like vim.
After trying I got something working and it looks like that :
with import <nixpkgs> {};
neovim.override {
configure = {
customRC = ''
syn on
set tabstop=2
set shiftwidth=2
set sts=2
set smarttab
set expandtab
set autoindent
set hls
set ruler
set splitbelow
set splitright
set number
...
'';
};
<plugins will go there>
}
This is for the configuration part.
Then goes the plugin part :
packages.myVimPackage = with pkgs.vimPlugins; {
start = [ vim-one vim-nix nerdtree coc-nvim fzf vim-airline vim-airline-themes vim-nerdtree-syntax-highlight nerdtree-git-plugin fugitive vim-devicons salt-vim vim-terraform neomux rust-vim salt-vim vim-devicons ];
opt = [ ];
};
Here there is quite some plugins and some were not packaged by Nix by default.
So I had to had some custom and still with Nix (it was quite easy in the end) and here is the full file :
let
neomux = pkgs.vimUtils.buildVimPlugin {
name = "neomux";
src = pkgs.fetchFromGitHub {
owner = "nikvdp";
repo = "neomux";
rev = "7fa6754f3c781ca99fd533217443b1e4f86611d4";
sha256 = "sha256-6Gr6/soyN5r+NRpDrFs9aT/assuQF9ydR3TfZnPlygI=";
};
};
vim-devicons = pkgs.vimUtils.buildVimPlugin {
name = "vim-devicons";
src = pkgs.fetchFromGitHub {
owner = "ryanoasis";
repo = "vim-devicons";
rev = "a2258658661e42dd4cdba4958805dbad1fe29ef4";
sha256 = "sha256-bS1vUKzdzUZ1RYDbYWujF2z8EOd9o01/0VqMYUaNihA=";
#sha256 = "0000000000000000000000000000000000000000000000000000";
};
};
in
neovim.override {
configure = {
customRC = ''
syn on
set tabstop=2
set shiftwidth=2
set sts=2
set smarttab
set expandtab
set autoindent
set hls
set ruler
set splitbelow
set splitright
set number
...
'';
packages.myVimPackage = with pkgs.vimPlugins; {
start = [ vim-one vim-nix nerdtree coc-nvim fzf vim-airline vim-airline-themes vim-nerdtree-syntax-highlight nerdtree-git-plugin fugitive vim-devicons salt-vim vim-terraform neomux rust-vim salt-vim vim-devicons ];
opt = [ ];
};
};
}
There was some stuff I was not aware like how to get the sha256 from the repo and as we can see in the vim-devicons there is a comment that can help you with that.
The first moment you’ll try to install Nix will show you the real sha256.
And finally to install this config simply run :
nix-env -f vim.nix -i neovim
And you can start working.