Setting Up Vim on NixOS
A month ago this jekyll-powered blog was hosted on GitHub pages. Now it’s served by NixOS hosted on DigitalOcean. Because many parts of NixOS are rarely documented I’d like to share how I’ve resolved the issues I’ve encountered in the process.
The first thing I did after booting into the fresh installed NixOS was trying to check out the default configuration /etc/nixos/configuration.nix
with vim
. Turns out vim is not installed by default.
Setting Up Vim
Setting up a plain vim installation on NixOS is rather simple. Just append vim to the list of system packages:
There are two ways to do this:
- either you use the
nano
text editor which is installed by default, or - you download the
/etc/nixos/configuration.nix
file, update it locally and then reupload it.
After this is done just run nixos-rebuild switch
and you should be able to run vim
.
A Custom vimrc
NixOS still doesn’t feel like home without my custom vimrc settings. So this was my next task. After googling around and looking at some other people’s configuration.nix
I used the following approach:
As you can see adding custom entries to .vimrc
is pretty simple. But it’s kind of ugly to have this huge expression inside of the configuration.nix
. Luckily we can just move the whole vim configuration into another file.
So let’s create a file vim.nix
in /etc/nixos
with the content of the above vim-expression:
Inside the configuration.nix
we just need to import the vim.nix
like this:
After running nixos-rebuild switch
vim should now use the specified vimrc settings.
Plugins
My vim experience is not complete without plugins. After spending some more time on google and inside the nixpkgs repository, I’ve found a pretty simple solution on how to configure vim plugins: vim_configurable
supports plugins out of the box.
We just have to specify the plugins we need inside the vim.nix
file:
Be aware that only the most common vim plugins are available by default. Here is the list of available plugins.
Just a quick nixos-rebuild switch
and the plugins should be ready.
Sharing The Configuration Across Different Computers
The vim.nix
placed on the server running this blog is equivalent to the .vimrc
running on my local OSX machine. Because the nix package manager is also available for OSX it should be possible to install the vim.nix
locally. So it’s possible to have the same vim setup on localhost and on a remote machine.
I haven’t tried this out yet, but I’m pretty sure this is possible. Feel free to try it out.
Update: It’s working :) You can just run nix-env -f vim.nix -i vim
on OSX to install the vim.nix
-package.
Takeaways
Customizing vim on NixOS is pretty simple once you know how to do it.
Thanks for reading :) Follow me on twitter if you’re interested in more of this stuff! In case you spotted a mistake above or something is not working, feel free to contact me.
Hey! I’m Marc, founder of digitally induced. I love playing with exciting new technology. Feel free to contact me.
If you liked this post feel free to subscribe to my mailing list.