From: Alyssa Ross <hi@alyssa.is>
To: devel@spectrum-os.org
Cc: Demi Marie Obenour <demiobenour@gmail.com>
Subject: [PATCH v3 3/3] host/rootfs: add run-flatpak script
Date: Thu, 27 Nov 2025 21:23:15 +0100 [thread overview]
Message-ID: <20251127202311.42422-7-hi@alyssa.is> (raw)
In-Reply-To: <20251127202311.42422-2-hi@alyssa.is>
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.
I've tested this by copying my host's Flatpak repository into a disk
image, and attaching that as a drive to the VM.
Signed-off-by: Alyssa Ross <hi@alyssa.is>
---
v3: pass $@ to mount-flatpak rather than each individual argument.
v2: https://spectrum-os.org/lists/archives/spectrum-devel/20251124195921.24441-1-hi@alyssa.is/
host/rootfs/default.nix | 10 +++---
host/rootfs/file-list.mk | 1 +
host/rootfs/image/usr/bin/run-flatpak | 51 +++++++++++++++++++++++++++
3 files changed, 58 insertions(+), 4 deletions(-)
create mode 100755 host/rootfs/image/usr/bin/run-flatpak
diff --git a/host/rootfs/default.nix b/host/rootfs/default.nix
index 941c04e..c93a06b 100644
--- a/host/rootfs/default.nix
+++ b/host/rootfs/default.nix
@@ -11,8 +11,9 @@ pkgsStatic.callPackage (
{ spectrum-host-tools
, lib, stdenvNoCC, nixos, runCommand, writeClosure, erofs-utils, s6-rc
, busybox, cloud-hypervisor, cryptsetup, dbus, execline, inkscape
-, iproute2, inotify-tools, jq, mdevd, s6, s6-linux-init, socat
-, util-linuxMinimal, virtiofsd, xorg, xdg-desktop-portal-spectrum-host
+, iproute2, inotify-tools, jq, mdevd, mount-flatpak, s6, s6-linux-init
+, socat, util-linuxMinimal, virtiofsd, xorg
+, xdg-desktop-portal-spectrum-host
}:
let
@@ -34,8 +35,9 @@ let
packages = [
cloud-hypervisor cryptsetup dbus execline inotify-tools iproute2
- jq mdevd s6 s6-linux-init s6-rc socat spectrum-host-tools
- util-linuxMinimal virtiofsd xdg-desktop-portal-spectrum-host
+ jq mdevd mount-flatpak s6 s6-linux-init s6-rc socat
+ spectrum-host-tools util-linuxMinimal virtiofsd
+ xdg-desktop-portal-spectrum-host
(busybox.override {
# Use a separate file as it is a bit too big.
diff --git a/host/rootfs/file-list.mk b/host/rootfs/file-list.mk
index 7625c54..67529c0 100644
--- a/host/rootfs/file-list.mk
+++ b/host/rootfs/file-list.mk
@@ -43,6 +43,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..f7b9bc4
--- /dev/null
+++ b/host/rootfs/image/usr/bin/run-flatpak
@@ -0,0 +1,51 @@
+#!/bin/execlineb -W
+# SPDX-License-Identifier: EUPL-1.2+
+# SPDX-FileCopyrightText: 2024-2025 Alyssa Ross <hi@alyssa.is>
+
+backtick -E dir { mktemp -d /run/vm/by-id/XXXXXX }
+backtick -E id { basename -- $dir }
+
+if {
+ elgetpositionals
+
+ 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 $@ }
+ 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 }
+}
+
+if { s6-instance-delete -- /run/service/vm-services $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
next prev parent reply other threads:[~2025-11-27 20:27 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-27 20:23 [PATCH v3 1/3] tools/mount-flatpak: init Alyssa Ross
2025-11-27 20:23 ` [PATCH v3 2/3] img/app: run Flatpak applications Alyssa Ross
2025-11-27 20:23 ` Alyssa Ross [this message]
2025-11-29 1:49 ` [PATCH v3 1/3] tools/mount-flatpak: init Demi Marie Obenour
2025-11-29 19:00 ` Alyssa Ross
2025-11-29 20:10 ` Demi Marie Obenour
2025-11-30 17:24 ` Alyssa Ross
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251127202311.42422-7-hi@alyssa.is \
--to=hi@alyssa.is \
--cc=demiobenour@gmail.com \
--cc=devel@spectrum-os.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://spectrum-os.org/git/crosvm
https://spectrum-os.org/git/doc
https://spectrum-os.org/git/mktuntap
https://spectrum-os.org/git/nixpkgs
https://spectrum-os.org/git/spectrum
https://spectrum-os.org/git/ucspi-vsock
https://spectrum-os.org/git/www
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).