Neovim and Flatpak

Recently I felt in love with NeoVim and NVChad, and I’m using them to develop software.

Unfortunately, my last assignment is to develop a software in an Ubuntu 18.04 environment, where the usual apt source that I’m using on my desktop machine doesn’t work.

A friend of mine suggest me to try to use it with Flatpak.

Flatpak

If you lived under a rock for some time, Flatpak is a distribution-agnostic package manager for Linux.

Application under Flatpak runs sandboxed in a container, and solves the issue of using updated software without upgrading the whole distribution.

Installing Flatpak on ubuntu 18.08 is straightforwarding:

⚡ apt install flatpak

After install it, you need to add a repository to get packages from.

Lately, the repository of choice is FlatHub, which can be easily installed with:

⚡ flatpak remote-add --if-not-exists flathub https://dl.flathub.org/repo/flathub.flatpakrepo

NeoVim

Neovim can be installed with:

⚡ flatpak install flathub io.neovim.NeoVim

NVChad

NVChad installation is a bit tricky, because flatpak packages cannot access files on user home folder, so configuration files are placed in the ~/.var/app/ folder:

⚡ git clone https://github.com/NvChad/starter ~/.var/app/io.neovim.nvim/config/nvim

Now you can launch NeoVim with the command:

⚡ flatpak run io.neovim.NeoVim

Nodejs

NeoVim can use many LSP (Language Server Protocol) designed to run in VSCode, that can be installed through the Mason neovim package manager.

Developing in Python, my weapon of choice is pyright, that unfortunately is written in nodejs.

Since the Flatpak packages runs inside isolated sandboxed containers, we need to add also the Node flathub package:

⚡ 
flatpak install flathub org.freedesktop.Sdk.Extension.node24

Now that we have all the pieces in the right place, we only need a command line to start the thing up.

Since Flatpak packages are isolated each other, we need to instruct flatpak that the node20 package should be available inside the nvim package, setting the environment variable:

⚡ FLATPAK_ENABLE_SDK_EXT=node24

RipGrep

Ripgrep is required by telescope, and should be added to the flatpak neovim container.

⚡ wget https://github.com/BurntSushi/ripgrep/releases/download/14.1.1/ripgrep-14.1.1-x86_64-unknown-linux-musl.tar.gz

Once you downloaded and opened the targz, you need to put the rg executable inside of the nvim flatpak container.

⚡ cp rg /var/lib/flatpak/app/io.neovim.nvim/x86_64/stable/active/files/bin

Now you can check if the rg executable is available inside the neovim container with:

⚡ flatpak run --command=sh io.neovim.nvim

Finishing

I found that an alias is the perfect tool to forget all the steps above and enjoy programming:

alias vi='FLATPAK_ENABLE_SDK_EXT=node24 flatpak run io.neovim.nvim'