Building Keybase for Raspberry Pi

The Raspberry Pi 4 is a nice little powerful device. The official Linux distribution for the Pi, Raspbian. Unfortunately, it doesn’t have any prebuilt binaries for Keybase. Neither are they provided by Keybase themselves. Luckily, building it from the source is relatively painless. With the new more powerful version 4 of the pi, the time it takes is somewhat reasonable.

The goal of this blog post is to show how to set up a build environment that doesn’t require root access to the machine. Followed by that, all the different parts of Keybase is built.

Installing Go

The majority of Keybase is written in Go. It is possible to use the version of Go that is part of the package repository but it is not the latest. Plus it requires sudo permissions to install. Instead, the latest version can be downloaded from the official website.

There are two versions to pick from:

  • ARMv6 for 32-bit OS
  • ARMv8 for 64-bit OS

As of the time of writing, Raspian only has support for 32-bit ARM. If the Linux version used has support for 64-bit, select the ARMv8 build.

Download and extract the tar file. Place the folder somewhere in your home folder, for example under $HOME/.pkgs. Make sure the path to the bin folder is added to the $PATH by for example adding export PATH=$PATH:$HOME/.pkgs/go/bin to the $HOME/.profile file followed by executing source ~/.profile.

If you would like to use a different path for installed Go packages, set the $GOPATH variable too. By default, Go uses $HOME/go for the path. Add $GOPATH/bin to the $PATH variable too, to ensure the shell can find the installed Go packages.

Installing Keybase Daemon

Installing the Keybase daemon is straight forward and can be done with the two following commands:

go get -u -v github.com/keybase/client/go/keybase
go install -v -tags production github.com/keybase/client/go/keybase

If you wish to install a specific version, just navigate to $GOPATH/src/github.com/keybase/client and use git to checkout the release tag before executing the go install command. For example to install version 5.2.0, execute:

go get -u -v github.com/keybase/client/go/keybase
cd $GOPATH/src/github.com/keybase/client
git checkout v5.2.0
go install -v -tags production github.com/keybase/client/go/keybase

Installing KBFS

The file share functionality is provided via a fuse driver. This driver is also used for the git functionality. If you have fuse installed, the driver and git hook can be compiled and installed with the two commands below.

go install -v -tags production github.com/keybase/client/go/kbfs/kbfsfuse
go install -v -tags production github.com/keybase/client/go/kbfs/kbfsgit/git-remote-keybase

Configure

The location where the file share is mounted can be configured with the command below. Use it to change the location to for example $HOME/Keybase.

keybase config set mountdir {path/to/folder}

To run the daemons, Keybase provides systemd.service files. They are located in the folder github.com/keybase/client/packaging/linux/systemd/. To run the daemon and the kbfs service the following systemd files are needed:

  • keybase.service
  • kbfs.service

Place the files in the folder: $HOME/.config/systemd/user/.

As the executables are not located where the service file expects them to be, the service files need to be edited. Edit the two files so the path to the keybase binary is correct. For example in keybase.service, change the ExecStart value to the right path:

ExecStart=/path/to/keybase

Once the paths are correct, the services can be started you can log in:

systemd --user daemon-reload
systemd --user start keybase.service
systemd --user start kbfs.service
keybase login

It is not possible to use Keybase from the command line, including the git functionality.

Keybase GUI

Keybase provides a desktop app that’s using Electron. First download NodeJS. Unpack it and add the bin folder to the $PATH. To build it, yarn is also needed which can be installed using NPM. To perform a global package install into a folder in the home directory, run the following commands:

mkdir $HOME/.npm_global
echo "prefix=/home/pi/.npm_global"

Add the following line the to $HOME/.profile and source the file:

export PATH=$PATH:$HOME/.npm_global/bin

Install yarn by executing:

npm install -g yarn

As part of the GUI build, Electron is downloaded. Keybase uses their own file store to host builds. Unfortunately, they don’t include builds for 32-bit ARM. This can be worked around by applying the patch below to use the Electron Github releases instead.

diff --git a/shared/desktop/package.desktop.tsx b/shared/desktop/package.desktop.tsx
index d921e3e7c9..06efc5fd98 100644
--- a/shared/desktop/package.desktop.tsx
+++ b/shared/desktop/package.desktop.tsx
@@ -54,7 +54,7 @@ const packagerOpts: any = {
   dir: desktopPath('./build'),
   download: {
     mirrorOptions: {
-      mirror: 'https://kbelectron.keybase.pub/electron-download/',
+      mirror: 'https://github.com/electron/electron/releases/download/',
     },
   },
   electronVersion: 0,

Apply the patch by executing:

cd $GOPATH/src/github.com/keybase/client
git apply /path/to/patch/file

After this, it is time to build the GUI. The fetching of the dependencies takes about 20 minutes on the Pi 4 while building the Electron package takes about 12 minutes. To build, for example, Keybase 5.2.0 for 32-bit ARM execute:

cd $GOPATH/src/github.com/keybase/client/shared
yarn install
yarn run package -- --platform linux --arch armv7l --appVersion 5.2.0

At the end of the build, the path to the release folder is printed. Copy the folder to somewhere in the home folder. Copy over the systemd service file for the GUI to the user’s systemd service folder and update the path.

You can also use run_keybase shell script, located at github.com/keybase/client/packaging/linux/run_keybase to start all the service with one simple line.