Own Your Calendar & Contacts With OpenBSD, Baïkal, and FOSS Android

In this tutorial I explain how I use Baïkal running on OpenBSD to host my own calendar and address book, and how to consume them with FOSS apps on Android.

Feel free to skip the introduction if you just want to dive straight into the tutorial, it's just there to provide context for those who are new to these topics.

Introduction

Before I got back into self hosting, I was using Hey as an email provider. They do not provide a calendar, so I was still using Google calendar. To get away from Google, I just wanted a service that would just host my calendar for me, nothing else.

Now this was a while ago, but at least back then there were just no sane options. There was a plethora of bloated calendar products and startups, but none of them just offered a simple hosted calendar, incredible. Maybe I was looking for the wrong things?

The only other thing I found were email services that also provide a calendar, but I only wanted a calendar.

Now that I'm self hosting again, I thought surely this is a solved problem without having to run NextCloud or get a calendar as a module of some big and complex software. Enter Baïkal.

What is Baïkal?

Baïkal is a lightweight CalDAV+CardDAV server. It's written in PHP and uses MySQL or SQLite as a database.

Baïkal is a great example of a small and simple piece of software which does one thing and does it well. Well, it does two things, but it does them both really well.

What it boils down to is that we can self host a Baïkal server that allows you to manage calendars and address books using CalDAV and CardDAV via HTTP.

What are CalDAV and CardDAV?

CalDAV is an internet standard used to represent and communicate calendar data. CardDAV is the same thing but for contacts.

CalDAV and CardDAV are both implemented on top of WebDAV (Web Distributed Authoring and Versioning) which itself is an extension of HTTP. I'm not going to get into more details about this in this post as it's not really relevant.

Why OpenBSD?

In case you've not been exposed to OpenBSD before, it's an operating system focused on security and correctness, amongst other things.

It provides a really simple, batteries included way to host something like Baïkal. I run my OpenBSD machines on Vultr (affiliate link, non-affiliate link). They make it super easy to spin up a VPS with OpenBSD and the prices are great.

FOSS Android?

By FOSS Android I just mean a free (as in freedom (and beer in this case)) and open source software calendar and contacts applications for Android. I use the ones from Simple Mobile Tools, they are really good, but more on this later.

If you're on iOS, you can still follow this tutorial and skip the Android specific steps. As for iOS calendar applications, I guess you can use the built in one, I'm not sure what FOSS calendar applications are available for iOS.

Tutorial

We'll start by getting an OpenBSD VPS up and running, then we'll install and configure Baïkal on it. Once everything is up and running we'll install and configure Android applications to talk to our server.

Setting up OpenBSD

I'll be starting from a clean install of OpenBSD. I get there by deploying a new VPS on Vultr, but it should be the same as installing one yourself.

OpenBSD has pretty sane defaults, so I'm not going to be making any configuration changes. Create a user for yourself and setup credentials to SSH to the server, then things are good to go to install Baïkal.

Setting up Baïkal

Start by install Baïkal:

pkg_add baikal

Before configuring Baïkal, you probably want to sort out an SSL certificate for your web server. It's very quick and painless to do, the OpenBSD Handbook has great documentation for this.

Next, let's setup httpd to point to Baïkal. Thankfully the OpenBSD README for Baïkal has all the steps needed for setup. Here's what my httpd.conf looks like:

server "calendar.baak6.com" {
        listen on * tls port 443

        tls {
                certificate "/etc/ssl/calendar.baak6.com.fullchain.pem"
                key "/etc/ssl/private/calendar.baak6.com.key"
        }

        location "/.well-known/ca*dav" {
                block return 301 "http://calendar.baak6.com/baikal/dav.php"
        }

        location "/baikal/*.php*" {
                root "/baikal/html"
                request strip 1
                fastcgi socket "/run/php-fpm.sock"
                directory index index.php
        }

        location "/baikal/*" {
                root "/baikal/html"
                request strip 1
                directory index index.php
        }
}

server "calendar.baak6.com" {
        listen on * port 80
        location "/.well-known/acme-challenge/*" {
                root "/acme"
                request strip 2
        }
}

The first server block makes Baïkal available at https://calendar.baak6.com/baikal/ (made up URL for this tutorial) via HTTPS and the second server block just redirects any non-HTTPS traffic to HTTPS.

Next up you have the choice between MySQL and SQLite. I use SQLite since it is a lot simpler and suitable for my needs. Install the PHP module for SQLite, when it asks for a version, pick the one that matches your PHP version.

pkg_add php-pdo_sqlite

Next up we need to enable SQLite in PHP. Open up /etc/php-8.0.ini and uncomment (remove the ;) the following line:

;extension=pdo_sqlite

Now enable and start PHP and httpd:

rcctl enable php80_fpm
rcctl start php80_fpm
rcctl enable httpd
rcctl start httpd

Now you should be able to navigate to https://calendar.baak6.com/baikal/admin/ (replace with your server's hostname of course) and complete the setup, create an account, etc.

I have an admin account for managing the server and a separate user account for myself. Once you've created a user account for yourself in Baïkal you can start using managing your calendar and contacts with a client. I'll demonstrate how to do this with FOSS Android applications.

Setting up Android

In this section we'll go through installing and setting up Simple Calendar and Simple Contacts, and having them use your Baïkal server using DAVx⁵.

I use F-Droid to install these applications, but you might be able to find them on other platforms.

Setting up DAVx⁵

On Android the OS normally takes care of abstracting things like calendar and contacts from your applications. This is done under Passwords & Accounts in settings and depending on your device and what applications you have, certain platforms will be available, like Google, Facebook, etc.

To make our Baïkal server available, we need to install DAVx⁵ and point it to our server. It will make the calendars and contacts on whatever you point it to available on your phone, that's all it does.

So head to F-Droid and find DAVx⁵, then install it.

Once it's installed, open it up and add an account. Select Login with URL and user name, then put in your username and password.

For the base URL, put in https://calendar.baak6.com/baikal/dav.php/, replacing the hostname with your server of course.

Once you authenticate, you should see your calendars under the CALDAV tab and your address books under CARDDAV. There you can choose which ones to enable, if you created multiple, and you can also create, delete, and update them.

In case you run into trouble with URLs in this step (I recall that happening to me), here are example URLs for a calendar and address book on my setup. My calendar is just called calendar and my address book is called contacts.

https://calendar.baak6.com/baikal/dav.php/calendars/baak6/calendar
https://calendar.baak6.com/baikal/dav.php/addressbooks/baak6/contacts

Now calendars and contacts from your Baïkal server should be available on your Android device.

Using Simple Calendar & Simple contacts

Go back to F-Droid and install Simple Contacts and Simple Calendar.

Then open them up and your calendar events and address book contacts should be visible to you.

Now your setup is complete, start using your new calendar and address book. I manually migrated my data over, I'll leave it up to you to figure that part out.

But, before you leave, setup a backup process for your server. At least back up the SQLite database regularly if nothing else.

Conclusion

In this tutorial we went through setting up Baïkal on OpenBSD, configuring DAVx⁵ to connect to Baïkal and using Simple Contacts and Simple Calendar to view your address books and calendars.

Now you have full control over your calendar and address book data and a fully end to end open source experience (assuming you run a FOSS Android based OS).

0
Subscribe to my newsletter

Read articles from Heidar Bernhardsson directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Heidar Bernhardsson
Heidar Bernhardsson

Writer for Semaphore and ButterCMS. Previously Staff Engineer at Deliveroo and in technical leadership at various public sector organisations.