[PATCH 3/3] host/rootfs: add run-flatpak script

Alyssa Ross
2025-11-13T12:05:18Z

This is the entrypoint for running Flatpak applications.

It would be good to only add mounts for the VM in virtiofsd's mount
namespace, so we don't need to do lots of manual unmounts, but that's
a wider change affecting more than just Flatpak.

Signed-off-by: Alyssa Ross <hi@alyssa.is>
---
host/rootfs/file-list.mk | 1 +
host/rootfs/image/usr/bin/run-flatpak | 56 +++++++++++++++++++++++++++
2 files changed, 57 insertions(+)
create mode 100755 host/rootfs/image/usr/bin/run-flatpak

diff --git a/host/rootfs/file-list.mk b/host/rootfs/file-list.mk
index 9acaa1d..a796b90 100644
--- a/host/rootfs/file-list.mk
+++ b/host/rootfs/file-list.mk
@@ -48,6 +48,7 @@ FILES = \
image/usr/bin/assign-devices \
image/usr/bin/create-vm-dependencies \
image/usr/bin/run-appimage \
+ image/usr/bin/run-flatpak \
image/usr/bin/run-vmm \
image/usr/bin/vm-console \
image/usr/bin/vm-import \
diff --git a/host/rootfs/image/usr/bin/run-flatpak b/host/rootfs/image/usr/bin/run-flatpak
new file mode 100755
index 0000000..39ee17b
--- /dev/null
+++ b/host/rootfs/image/usr/bin/run-flatpak
@@ -0,0 +1,56 @@
+#!/bin/execlineb -S2
+# SPDX-License-Identifier: EUPL-1.2+
+# SPDX-FileCopyrightText: 2024 Alyssa Ross <hi@alyssa.is>
+
+backtick -E dir { mktemp -d /run/vm/by-id/XXXXXX }
+backtick -E id { basename -- $dir }
+
+if { mkdir -p /run/configs/${id}/fs }
+if { redirfd -w 1 /run/configs/${id}/fs/type echo flatpak }
+if { cd /run/configs/${id}/fs mount-flatpak $1 $2 }
+if {
+ ln -s /usr/lib/spectrum/img/appvm/blk /usr/lib/spectrum/img/appvm/vmlinux
+ /run/configs/${id}
+}
+
+if { ln -s /run/configs/${id} ${dir}/config }
+
+if { create-vm-dependencies $id }
+
+piperw 4 3
+background {
+ fdclose 3
+ fdmove 0 4
+
+ # Wait for the VMM to be up, then start the VM.
+ if { redirfd -w 1 /dev/null head -1 }
+ vm-start $id
+}
+fdclose 4
+
+foreground { run-vmm $id }
+fdclose 3
+
+if {
+ forx -pE service {
+ dbus
+ vhost-user-fs
+ vhost-user-gpu
+ xdg-desktop-portal-spectrum-host
+ }
+ s6-instance-delete /run/service/${service} $id
+}
+
+if {
+ elglob -0 flatpak_dir_mounts /run/configs/${id}/fs/flatpak/*/*/*/*/*
+ forx -E mount {
+ ${dir}/fs/doc
+ /run/configs/${id}/fs/flatpak/repo/config
+ $flatpak_dir_mounts
+ /run/configs/${id}/fs/flatpak
+ ${dir}/fs/config
+ }
+ umount $mount
+}
+
+rm -r $dir /run/configs/${id}
--
2.51.0