Installing Neovim on NetBSD

I have a certain Vim setup with Neovim being my choice of Vim. I’ve been playing around with NetBSD recently, but I did not find a stable package available for Neovim in the official package repositories. When I went about building it however, I faced a couple of challenges. I thought it might be a good idea to document it for anyone else facing the same.

Let’s start by fetching Neovim and uncompressing its source code:

wget https://github.com/neovim/neovim/archive/v0.4.3.tar.gz
tar xvzf v0.4.3.tar.gz
cd neovim-0.4.3/

Next, let’s install the pre-requisite NetBSD packages Neovim requires to build

sudo pkgin install cmake gmake libtool automake pkgconf unzip wget gettext

Let’s attempt to build Neovim:

gmake CMAKE_BUILD_TYPE=Release

We’re met with a panic message:

PANIC: unprotected error in call to Lua API (runtime code generation failed, restricted kernel?)

This is due to Lua checking if the JIT functionality is working and it being restricted by NetBSD’s security measures. The following commands temporarily disable memory protection so that we can continue compiling.

sudo sysctl -w security.pax.mprotect.global=0
sudo sysctl -w security.pax.mprotect.enabled=0

We can now continue building and installing Neovim

gmake CMAKE_BUILD_TYPE=Release
sudo gmake install

When running the nvim command, if you see an error message related to a missing library, libintl.so.8, add the following to your shell’s RC file, source the file or logout and login for changes to take effect:

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/pkg/lib

Remember we temporarily disabled memory protection? We don’t want to permanently do it for the whole system. To disable memory protection for the nvim binary so that it can run without problems run this command:

sudo /usr/sbin/paxctl -m /usr/local/bin/nvim

That’s all, folks!