Why NetBSD Installing NetBSD XDG_RUNTIME_DIR Installing river Window managers Troubleshooting


Why NetBSD

Recently I tried out NetBSD on an old laptop given the increased interest NetBSD has garnered over the past few months – namely for being one of the few OS bastions untouched by so called gen “AI”. I’ve always wanted to try out a BSD properly anyways, so I figured I’d jump the gun and install NetBSD on the closest laptop to me.

Installing NetBSD

I followed this amazing guide on how to install NetBSD manually with disk encryption. It went really well and I managed to get a booting system. I did manage to corrupt the filesystem with force reseting, so I opted to reinstall using the installation UI. Both methods of installing don’t change anything in this guide, just make sure that you have pkgin installed on your system.

XDG_RUNTIME_DIR

For river (and a lot of other desktop apps) to work, the $XDG_RUNTIME_DIR needs to be set. It needs to be set to a directory that the user (and only the user) has write access to and should not persist upon reboots or logouts. An earlier version of this guide got the user to set it to $HOME/.local, but are better ways to do it. You can learn more here if you are interested.

The simplest way to set it up on the first login is to edit the .profile file. Note: this will not run on each subsequent login, only the first, so there may be issues on relogging, although I have personally not encountered any.

# Create and export XDG_RUNTIME_DIR
export XDG_RUNTIME_DIR=/tmp/user/$(id -u)
mkdir -p $XDG_RUNTIME_DIR
chmod 0700 $XDG_RUNTIME_DIR

Upon rebooting, ensure that the directory exists and $XDG_RUNTIME_DIR points to the right directory.

# this directory should exist, be drwx------, and be in /tmp/user/id
# example: drwx------  3 user  wheel  144B Nov 26 12:24 /tmp/user/1000
ls -lahd $XDG_RUNTIME_DIR

Installing river

Dependencies

The first step is to install river’s dependencies.

pkgin install zig wayland wayland-protocols wlroots pixman pkg-config scdoc libevdev-chunk seatd

I don’t think seatd is strictly a dependency, but I found it easiest to start river using seatd-launch.

You will also want git (and/or wget or similar) to download the repo and other software.

pkgin install git wget

I also recommend these for any river user.

pkgin install foot grim

Using the right version of zig

Depending on what version of zig you have, you may need to get a newer one. Fortunately ziglang.org provides builds of zig for NetBSD. You can check the zig version with zig version. If it is lower than the required version needed to build river you can grab the latest version as shown next. Alternatively, you can git checkout an older version of river that is compatible with your zig version.

The version of zig in the pkgsrc repos as I write this is 0.16.0, whereas the version required to build the latest version of river is 0.17.1. You may need to change the version number in the following example.

mkdir -p ~/.local/bin
cd ~/.local/bin
wget https://ziglang.org/download/0.17.1/zig-x86_64-netbsd-0.17.1.tar.xz
tar xvf zig-x86_64-netbsd-0.17.1.tar.xz

Building river

Building river with the version of zig that was just downloaded is pretty simple. The following will install river to your ~/.local/bin. Note: for Xwayland support the -Dxwayland compile flag must be passed.

mkdir ~/repos && cd ~/repos
git clone https://codeberg.org/river/river
cd river
# without Xwayland
~/.local/bin/zig-x86_64-netbsd-0.17.1/zig build -Doptimize=ReleaseSafe --prefix ~/.local install
# with Xwayland support
~/.local/bin/zig-x86_64-netbsd-0.17.1/zig build -Doptimize=ReleaseSafe -Dxwayland --prefix ~/.local install

Confirm everything is working

Time to confirm that river is working. XDG_RUNTIME_DIR needs to be set to a directory for river to function and using seatd-launch is the simplest way to launch river from what I can tell.

seatd-launch ~/.local/bin/river

If river launches you should see a mouse cursor and black background. River can be killed now. If it doesn’t launch then something went wrong.

Window managers

Starting with river 0.4.0, a window manager is required for river to be used properly. There are several to choose from. I will be showing you how to install and use a couple of them. You only need one of them, but you can run river from within river if you want to use multiple window managers at once (I do this for a specific application that really does not like my tiling window manager, but tolerates a stacking one).

CoW

CoW is a stacking window manager. It has a few steps to install on NetBSD. Note: this will install cow to the system and not locally to ~/.local/bin.

# dependencies
pkgin install meson bison pango libevent

# download cow
cd ~/repos
git clone https://codeberg.org/cow-wm/cow
cd cow

# build
meson setup build
meson compile -C build && meson install -C build

And to run cow from river.

seatd-launch ~/.local/bin/river -c cow

Beansprout

Beansprout is a tilling window manager (my favourite!). As of v1.3.0 it has support for NetBSD (and also FreeBSD). The release provides binaries so you can either compile it or download and extract a binary from the releases page. While the binary originally did not work on my machine it has since been fixed.

# option 1: compile from source (install locally)
cd ~/repos
git clone https://codeberg.org/beansprout/beansprout
cd beansprout
~/.local/bin/zig-x86_64-netbsd-0.17.1/zig build -Doptimize=ReleaseSafe --prefix ~/.local install

# option 2: use binary (install to system)
# replace "version" with the version you are installing
wget https://codeberg.org/beansprout/beansprout/releases/download/version/beansprout-version-netbsd-x86_64.tar.gz
tar xvf beansprout-version-netbsd-x86_64.tar.gz --directory /usr/local/
rm beansprout-version-netbsd-x86_64.tar.gz

And to run beansprout from river.

# replace the beansprout path with /usr/local/bin/beansprout if you installed it system-wide
seatd-launch ~/.local/bin/river -c ~/.local/bin/beansprout

Troubleshooting

pkgin install doesn’t work / is really slow

The mirror that is selected is probably over utilised or currently down. Try changing the pkgsrc mirrors to one of these https://www.netbsd.org/mirrors/

vi /usr/pkg/etc/pkgin/repositories.conf
# add your preferred mirror

firefox won’t open and segfaults

Try exporting MOZ_ENABLE_WAYLAND=0 before running firefox.

export MOZ_ENABLE_WAYLAND=0
firefox