sector-f-linux

Sector F Linux
git clone https://git.sectorflabs.com/sector-f-linux.git
Log | Files | Refs | README | LICENSE

commit c38fffda0283ca856b00100ecaa449ac5e0a92ec
parent cc8390bbebd95067ef1adb1efafb7a9e9aa3dbb4
Author: Divan Visagie <me@divanv.com>
Date:   Thu, 29 Oct 2026 18:12:20 +0100

Patina desktop on FreeBSD hardware: setup.sh and the notes behind it

freebsd/hardware.md: drm-kmod and seatd, building and installing the desktop,
Teleprinter and Files, what was wrong and what fixed it, the tailnet.
hardware/setup.sh does it from scratch over ssh, idempotently.

Diffstat:
Mfreebsd/README.md | 4+++-
Afreebsd/hardware.md | 202+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Afreebsd/hardware/profile.sh | 15+++++++++++++++
Afreebsd/hardware/setup.sh | 123+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Afreebsd/hardware/start-patina | 12++++++++++++
5 files changed, 355 insertions(+), 1 deletion(-)

diff --git a/freebsd/README.md b/freebsd/README.md @@ -49,5 +49,7 @@ worked around: - **/home stayed put** through every switch: a file written there was the same in every boot environment. -Not tried here: the desktop on real graphics (drm-kmod), a login screen, and building a boot +The desktop on real graphics (drm-kmod, seatd) is in [hardware.md](hardware.md). + +Not tried here: a login screen, and building a boot environment from a recipe on a build machine rather than by hand in the VM. diff --git a/freebsd/hardware.md b/freebsd/hardware.md @@ -0,0 +1,202 @@ +# Patina desktop on FreeBSD hardware + +The VM in `README.md` runs the desktop nested, because QEMU's graphics have no FreeBSD driver. +This is the other half: a real machine, with the desktop as the session on its own display. + +Done on 2026-10-29 on `loki`, a ThinkPad (11th Gen i5-1135G7, Intel Iris Xe, 16 GB) with a fresh +FreeBSD 15.1-RELEASE on a ZFS root (`zroot/ROOT/default`, `zroot/home`), over ssh. Every command +below is as the normal user with `doas`. + +To do all of it from scratch, from this repository, and again whenever the desktop changes: + +``` +freebsd/hardware/setup.sh loki # PATINA_GPU=, PATINA_SCALE= (default 1.2) choose firmware and scale +``` + +It is safe to run twice; the steps below are what it does. It also installs Teleprinter +(the terminal) and Files, from their checkouts beside this repository, with their launcher +entries and Files' file chooser portal, and the portal packages. `PATINA_WORKTREE=1` sends the +checkouts' working trees instead of their last commits. + +## 0. A way back + +``` +doas bectl create pre-wayland +``` + +A boot environment of the system before any change. If the graphics driver ever stops the +machine booting, pick `pre-wayland` at the loader's boot-environment menu, or `bectl activate +pre-wayland` from a rescue shell. `/home` is shared by all of them, so nothing there is lost. + +## 1. Preparing for Wayland + +FreeBSD has no KMS driver in the base system; the DRM drivers are ports of Linux's, built as +kernel modules against the exact release (`drm-kmod`). With them in place, what a Wayland +compositor needs is a DRM device, a way to open it and the input devices without root (seatd, in +place of systemd-logind), libinput, Mesa and a runtime directory. + +``` +doas pkg install drm-kmod gpu-firmware-intel-kmod-tigerlake \ + mesa-dri mesa-libs libdrm seatd libinput libudev-devd evdev-proto \ + libxkbcommon pixman wayland wayland-protocols xwayland pkgconf \ + dbus dejavu noto-basic foot grim +``` + +- `drm-kmod` is the metaport; on 15.1 it brings `drm-612-kmod` (Linux 6.12's drivers). +- The firmware package is per GPU generation: `pciconf -lv | grep -A3 vga` says which (Tiger + Lake here; the others are `gpu-firmware-intel-kmod-*`, or `gpu-firmware-amd-kmod-*` for AMD). +- `libudev-devd` and `evdev-proto` are how libinput finds the keyboard and touchpad on FreeBSD, + which has no udev. +- Fonts: a new install has none, and without them foot and anything else with text fails + (`failed to match font`). The desktop's own pieces carry their font. + +Then configure it, and load the driver without rebooting to see it work: + +``` +doas sysrc kld_list+="i915kms" # amdgpu for AMD +doas sysrc seatd_enable=YES +doas sysrc dbus_enable=YES +doas pw groupmod video -m $USER # seatd's socket is root:video, 0770 +doas service seatd start +doas service dbus start +doas kldload i915kms +``` + +After `kldload`, `/dev/dri/card0` and `renderD128` exist, `dmesg` says `[drm] Initialized i915` +and the console switches from `efifb` to `drmfb`. Over ssh that call can hang for a while as +the console changes; the machine is fine, reconnect. Log out and in again for the `video` group. + +Not needed here: a `devfs.rules` for `/dev/dri` or `/dev/input`. seatd opens them as root and +hands them to the compositor, which is the point of it. + +## 2. Building the desktop + +``` +doas pkg install git rust cmake-core llvm shaderc vulkan-headers vulkan-loader \ + alsa-lib alsa-plugins +``` + +This is `make deps`' FreeBSD line, except that cmake's package is `cmake-core`, not `cmake`. + +patina-desktop is on a private remote, which the machine has no key for, so it's sent from a +checkout over ssh (the same last commit `stage.sh` copies into the VM). Its dependencies +(patina, patina-shell, patina-apps, the Smithay fork) are public GitHub repositories and cargo +fetches them itself. + +``` +# on the machine +mkdir -p ~/src/patina-desktop ~/src/patina-launcher + +# on the one with the checkouts, from the folder holding both +for p in patina-desktop patina-launcher; do + git -C $p archive HEAD | ssh loki "tar -x -C ~/src/$p" +done + +# on the machine +cd ~/src/patina-desktop && cargo build --release # 11.5 minutes on 8 cores +cd ~/src/patina-launcher && cargo build --release # 3.5 minutes +``` + +## 3. Installing it + +`make install` is for Linux (it writes a GDM session and PAM file, and wants `target/launcher/`), +so on FreeBSD the programs and their man pages are copied directly: + +``` +cd ~/src/patina-desktop +doas install -m 755 $(find target/release -maxdepth 1 -type f -perm -u+x -name 'patina-*') \ + ../patina-launcher/target/release/patina-launcher /usr/local/bin/ +doas install -m 644 man/*.1 /usr/local/share/man/man1/ +doas install -m 644 man/*.7 /usr/local/share/man/man7/ +``` + +and, from this repository, the start script: + +``` +scp freebsd/hardware/start-patina loki:/tmp/ +ssh loki doas install -m 755 /tmp/start-patina /usr/local/bin/start-patina +``` + +`hardware/start-patina` is what a console login runs. FreeBSD has no logind to make +`XDG_RUNTIME_DIR` and no session bus, and the desktop needs both, so it makes +`/tmp/xdg-<uid>` and starts the session inside `dbus-run-session`. + +## 4. Running it + +Log in at the text console and run: + +``` +start-patina +``` + +First start on `loki`: + +``` +patina-compositor: on eDP-1 at 1920x1200, scale 1.5 +patina-compositor: clients connect on WAYLAND_DISPLAY=wayland-1 +patina-compositor: X11 apps connect on DISPLAY=:0 +``` + +The scale is set to 1.2 in `~/.config/patina-compositor/config.toml` (`setup.sh` does it). The wallpaper, the bar, the clock and the power button came up on the panel, at its own +resolution with scale 1.5 chosen from its density; `foot` opened as a window with its tab in the +bar. It was started over ssh during setup (`XDG_RUNTIME_DIR=/tmp/xdg-1001 dbus-run-session +patina-session --session`), not from the console. A screenshot from the machine itself: +`XDG_RUNTIME_DIR=/tmp/xdg-1001 WAYLAND_DISPLAY=wayland-1 grim shot.png`. + +Ctrl+Alt+Backspace quits the compositor, the way out; Ctrl+Alt+Shift+Backspace restarts it. + +## On the tailnet + +Joined the way the registry host was (the infrastructure repo's tailscale setup), to headscale on the headscale server: + +``` +doas pkg install tailscale +doas sysrc tailscaled_enable=YES +doas service tailscaled start +doas tailscale up --login-server=https://headscale.example.com # prints a register URL +# on the headscale server, at once (the key expires in minutes): +doas headscale --config /etc/headscale/config.yaml auth register --auth-id hskey-authreq-... --user USER +``` + +It registers under the machine's hostname, `loki`, as 100.64.0.3. Don't pass `--hostname`: the +name should be the machine's own, as the others are. (The earlier `loki`, the Home Assistant host +retired on 2026-10-07, had the same name and address; its node was deleted, so a stale +`known_hosts` entry for `loki` fails with a changed host key: `ssh-keygen -R loki`.) + +## Things that were wrong, and what fixed them + +| Symptom | Cause | Fix | +|---|---|---| +| Settings (and every egui app) has a window and a bar tab but draws nothing | eframe's wgpu draws nothing through Mesa's Vulkan on this machine (`Failed to create surface for any enabled backend`) | `WGPU_BACKEND=gl`, set by `start-patina` for everything it starts | +| Locked out: the lock screen never accepts the password | `patina-lock` checks it through a PAM service, `patina-lock`, which Linux's `make install` writes and this setup doesn't; and a non-root program can't check a password against FreeBSD's `master.passwd` anyway | `[lock] command = ""` and the two other lock settings off in `~/.config/patina-compositor/config.toml`, which `setup.sh` does. To get out of a lock already on: remove `/tmp/xdg-<uid>/*.locked` (the compositor starts locked while it's there) and restart the session | +| No battery in the bar | patina-system read `/sys/class/power_supply` | the battery from `sysctl hw.acpi.battery.*` and `acpiconf` (patina-desktop ADR-0095) | +| Wi-Fi menu can't open | patina-system talked to NetworkManager | wpa_supplicant through `wpa_cli` (ADR-0095); `update_config=1` in `/etc/wpa_supplicant.conf` so joined networks are saved, which `setup.sh` adds | +| Teleprinter and Files had no launcher entry or icon | they come from each project's `make install`, which uses `install -D` | `setup.sh` installs the entries and icons itself | +| `Failed to connect to ... /bus` | no session bus | `dbus-run-session`, in `start-patina` | +| foot: `failed to match font` | a new install has no fonts | `dejavu`, `noto-basic` | + +## What it still prints, and what it means + +| Message | Meaning | +|---|---| +| `logind Inhibit: ... login1 was not provided` | no logind on FreeBSD: it can't hold off suspend while a window plays; harmless | +| `patina-dictate: no model at ...ggml-base.en.bin` | dictation's speech model isn't downloaded (the URL is in the message) | +| foot: `compositor does not implement the primary selection interface` etc. | protocols the compositor doesn't offer yet; foot works without | + +## Not done, not tested + +- **A login screen.** `start-patina` from a console login is all there is. greetd with a Patina + entry is the next thing; `patina.desktop` and the PAM file (`make install`) are Linux's. +- **The lock screen.** Off, as above. Wanted: a `patina-lock` PAM service for FreeBSD that works + for a user's own password, or a locker that's allowed to read it. +- **Volume, brightness and power menus.** Volume goes through `wpctl` (PipeWire's WirePlumber, + not installed) and brightness through `/sys/class/backlight`; FreeBSD has `mixer(8)` and + `backlight(8)`. Each wants an implementation behind a trait, as the battery and Wi-Fi have. +- **Wi-Fi off and on** runs `doas -n ifconfig wlan0 down|up`, which works here (doas without a + password) and nowhere else. +- **The battery's history graphs** (from UPower) and charging time (ACPI doesn't say). +- **Sleep and locking before it, `patina-dictate`'s model, Xwayland apps, screen recording.** +- **Keyboard and touchpad on the machine itself, and `start-patina` from the console.** The + session has been started over ssh. +- **Putting this in a boot environment recipe**, so it's part of the system that's shipped + rather than done by hand on one machine (`README.md`'s last paragraph). diff --git a/freebsd/hardware/profile.sh b/freebsd/hardware/profile.sh @@ -0,0 +1,15 @@ + +# >>> patina desktop (freebsd/hardware/setup.sh) >>> +# What patina-session needs, which it takes from here (it runs `sh -l`): the +# runtime dir FreeBSD has no logind to make, GL for egui's renderer (wgpu's +# Vulkan draws nothing through Mesa here), and a session bus, started once per +# console login and not for ssh. +XDG_RUNTIME_DIR=/tmp/xdg-$(id -u) +export XDG_RUNTIME_DIR +mkdir -p -m 700 "$XDG_RUNTIME_DIR" +WGPU_BACKEND=gl +export WGPU_BACKEND +if [ -z "$DBUS_SESSION_BUS_ADDRESS" ] && [ -z "$SSH_CONNECTION" ] && command -v dbus-launch >/dev/null; then + eval "$(dbus-launch --sh-syntax)" +fi +# <<< patina desktop <<< diff --git a/freebsd/hardware/setup.sh b/freebsd/hardware/setup.sh @@ -0,0 +1,123 @@ +#!/usr/bin/env bash +# Sets up the Patina desktop on a fresh FreeBSD 15 machine with an Intel GPU, from +# this one, over ssh; hardware.md says what each step is and why. Safe to run again: +# packages, rc.conf, the group and the install are checked or replaced, and cargo +# rebuilds only what changed. +# +# hardware/setup.sh [user@]host +# +# The host needs ssh and doas without a password for the user. It installs the +# desktop, its launcher, Teleprinter (the terminal) and Files, from their checkouts +# beside patina-os (PATINA_DESKTOP, PATINA_LAUNCHER, PATINA_TELEPRINTER, +# PATINA_FILES override where); PATINA_GPU is the firmware's generation (default: +# tigerlake), PATINA_SCALE the screen's scale (default: 1.2). PATINA_WORKTREE=1 sends +# the checkouts' working trees, uncommitted changes and all, instead of their last commits. +set -euo pipefail + +HOST=${1:?usage: setup.sh [user@]host} +HERE=$(cd "$(dirname "$0")" && pwd) +DESKTOP=${PATINA_DESKTOP:-$HERE/../../../patina-desktop} +LAUNCHER=${PATINA_LAUNCHER:-$HERE/../../../patina-launcher} +TELEPRINTER=${PATINA_TELEPRINTER:-$HERE/../../../teleprinter} +FILES=${PATINA_FILES:-$HERE/../../../files} +GPU=${PATINA_GPU:-tigerlake} +SCALE=${PATINA_SCALE:-1.2} + +run() { ssh "$HOST" "$@"; } + +echo "==> a way back: boot environment pre-wayland" +run 'bectl list -H | cut -f1 | grep -qx pre-wayland || doas bectl create pre-wayland' + +echo "==> packages" +run "doas pkg install -y drm-kmod gpu-firmware-intel-kmod-$GPU mesa-dri mesa-libs libdrm seatd \ + libinput libudev-devd evdev-proto libxkbcommon pixman wayland wayland-protocols xwayland \ + pkgconf dbus xdg-desktop-portal xdg-desktop-portal-gtk xdg-desktop-portal-wlr xdg-utils \ + desktop-file-utils shared-mime-info gvfs dejavu noto-basic foot grim git rust cmake-core llvm shaderc vulkan-headers \ + vulkan-loader alsa-lib alsa-plugins" + +echo "==> rc.conf, the video group, services" +run 'doas sysrc kld_list+=i915kms seatd_enable=YES dbus_enable=YES >/dev/null + doas pw groupmod video -m "$(id -un)" + doas service seatd start || true + doas service dbus start || true' + +echo "==> source" +ship() { # name checkout + [[ -d $2/.git ]] || { echo "error: no checkout at $2" >&2; exit 1; } + # Replace the sources, keep target/ so the build is incremental. + run "mkdir -p ~/src/$1 && find ~/src/$1 -mindepth 1 -maxdepth 1 ! -name target -exec rm -rf {} +" + if [[ -n ${PATINA_WORKTREE:-} ]]; then + git -C "$2" ls-files -z --cached --others --exclude-standard | tar -c -C "$2" --null -T - | run "tar -x -C ~/src/$1" + echo " $1 working tree (on $(git -C "$2" rev-parse --short HEAD))" + else + git -C "$2" archive HEAD | run "tar -x -C ~/src/$1" + echo " $1 $(git -C "$2" rev-parse --short HEAD)" + fi +} +ship patina-desktop "$DESKTOP" +ship patina-launcher "$LAUNCHER" +ship teleprinter "$TELEPRINTER" +ship files "$FILES" + +echo "==> build" +for p in patina-desktop patina-launcher teleprinter files; do + run "cd ~/src/$p && cargo build --release" +done + +echo "==> install" +run 'cd ~/src/patina-desktop && + doas install -m 755 $(find target/release -maxdepth 1 -type f -perm -u+x -name "patina-*") \ + ../patina-launcher/target/release/patina-launcher ../teleprinter/target/release/teleprinter \ + ../files/target/release/files /usr/local/bin/ && + doas install -m 644 man/*.1 /usr/local/share/man/man1/ && + doas install -m 644 man/*.7 /usr/local/share/man/man7/' +scp -q "$HERE/start-patina" "$HOST:/tmp/start-patina" +run 'doas install -m 755 /tmp/start-patina /usr/local/bin/start-patina' + +# What each project'"'"'s make install puts beside the program: icons, launcher entries +# (Exec made absolute), the file chooser portal, Patina'"'"'s portal choices. +run 'P=/usr/local S=/usr/local/share ICONS=/usr/local/share/icons/hicolor/scalable/apps + doas install -d $ICONS $S/applications $S/dbus-1/services $S/xdg-desktop-portal/portals \ + $P/etc/xdg/xdg-desktop-portal $P/etc/xdg/xdg-desktop-portal-wlr + cd ~/src/patina-desktop + for f in settings processes; do + d=$(ls $f/packaging/*.desktop); id=$(basename $d .desktop) + doas install -m 644 $f/packaging/$f.svg $ICONS/$id.svg + sed "s|^Exec=patina-$f|Exec=$P/bin/patina-$f|" $d | doas tee $S/applications/$id.desktop >/dev/null + done + doas install -m 644 packaging/patina-mimeapps.list $S/applications/ + doas install -m 644 packaging/portal/patina-portals.conf $P/etc/xdg/xdg-desktop-portal/ + sed "s|@BINDIR@|$P/bin|" packaging/portal/xdg-desktop-portal-wlr.ini | doas tee $P/etc/xdg/xdg-desktop-portal-wlr/Patina >/dev/null + cd ~/src/teleprinter + doas install -m 644 packaging/linux/teleprinter.svg $ICONS/com.sectorflabs.Teleprinter.svg + sed "s|^Exec=teleprinter|Exec=$P/bin/teleprinter|" packaging/linux/com.sectorflabs.Teleprinter.desktop | doas tee $S/applications/com.sectorflabs.Teleprinter.desktop >/dev/null + cd ~/src/files + doas install -m 644 packaging/linux/files.svg $ICONS/com.sectorflabs.Files.svg + sed "s|^Exec=files|Exec=$P/bin/files|" packaging/linux/com.sectorflabs.Files.desktop | doas tee $S/applications/com.sectorflabs.Files.desktop >/dev/null + sed "s|@BINDIR@|$P/bin|" packaging/portal/org.freedesktop.impl.portal.desktop.patina.service | doas tee $S/dbus-1/services/org.freedesktop.impl.portal.desktop.patina.service >/dev/null + doas install -m 644 packaging/portal/patina.portal $S/xdg-desktop-portal/portals/ + doas update-desktop-database -q $S/applications; true' + +echo "==> scale $SCALE" +run "c=~/.config/patina-compositor/config.toml + mkdir -p \$(dirname \$c) + if [ ! -f \$c ]; then echo 'scale = $SCALE' > \$c + elif grep -q '^scale *=' \$c; then sed -i '' 's/^scale *=.*/scale = $SCALE/' \$c + elif grep -q '^# scale *=' \$c; then sed -i '' 's/^# scale *=.*/scale = $SCALE/' \$c + else echo 'scale = $SCALE' >> \$c; fi + grep -n '^scale' \$c" + +echo "==> lock screen off" +# patina-lock checks passwords through PAM, which a non-root user can't do on FreeBSD +# as it stands: it would lock the screen for good. Off until that's solved. +run 'c=~/.config/patina-compositor/config.toml + grep -q "^command *= *\"\"" $c || awk '"'"'{print} /^\[lock\]/{print "command = \"\""; print "on_suspend = false"; print "on_screen_off = false"}'"'"' $c > /tmp/c.new && cp /tmp/c.new $c + grep -n -A3 "^\[lock\]" $c' + +echo "==> wpa_supplicant may save the networks it joins" +# Read when the supplicant starts. Not reconfigured here: that re-associates, and over +# Wi-Fi it would drop this very connection (so: wpa_cli reconfigure, or reboot). +run 'doas grep -q "^update_config=1" /etc/wpa_supplicant.conf || + doas sh -c "echo update_config=1 >> /etc/wpa_supplicant.conf"' + +echo "==> done. Reboot, log in at the console and run start-patina." diff --git a/freebsd/hardware/start-patina b/freebsd/hardware/start-patina @@ -0,0 +1,12 @@ +#!/bin/sh +# Starts the Patina desktop on the machine's own display, from a text console +# login: a runtime dir for the session (FreeBSD has no logind to make one), and +# a D-Bus session bus for the pieces that talk over it. Installed as +# /usr/local/bin/start-patina; see ../hardware.md. +XDG_RUNTIME_DIR=/tmp/xdg-$(id -u) +export XDG_RUNTIME_DIR +mkdir -p -m 700 "$XDG_RUNTIME_DIR" +# eframe's wgpu draws nothing through Mesa's Vulkan here, so every egui app uses GL. +WGPU_BACKEND=gl +export WGPU_BACKEND +exec dbus-run-session patina-session --session