From fe55ec24c15e873505d6ab2fc765fae4750d5f69 Mon Sep 17 00:00:00 2001 From: The412Banner <205237651+The412Banner@users.noreply.github.com> Date: Sat, 5 Dec 2026 12:16:26 +0000 Subject: [PATCH] fix(flatpak): give apps with host access the home folder and its ROMs mount --- docs/development/flatpak.md | 5 ++- .../usr/local/bin/droiddeck-flatpak-run | 17 +++++++--- tools/tests/test_game_gpu_launchers.py | 33 +++++++++++++++++-- 3 files changed, 47 insertions(+), 8 deletions(-) diff --git a/docs/development/flatpak.md b/docs/development/flatpak.md index dd7faae506..70befb4343 100644 --- a/docs/development/flatpak.md +++ b/docs/development/flatpak.md @@ -69,7 +69,10 @@ screen under gamescope. Under gamescope it passes `--nosocket=wayland --socket=x `XDG_SESSION_TYPE=x11`. Otherwise Flatpak finds the app compositor's `wayland-0` and the window opens behind gamescope. gamescope's own Wayland socket is no alternative: Chromium on Wayland asks the render node it names for a DRM version, which KGSL cannot give, and aborts. The -launcher also starts a session bus when there is none. On the Linux desktop, the apps' exported +launcher also starts a session bus when there is none. Flatpak's `host` permission skips `/root`, +since a desktop's homes live under `/home`, but the session's home is `/root`. An app granted `host` +and not `home` is therefore also given `home` in the same mode, which brings in the session's mounts +there, such as `/root/ROMs`. On the Linux desktop, the apps' exported menu entries appear in Plasma's launcher. Games are wrapped through `droiddeck-gpu` like the rootfs's own, since the desktop composites in software. diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-flatpak-run b/tools/linuxfs/overlay/usr/local/bin/droiddeck-flatpak-run index 38088653d9..0ee69c5212 100644 --- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-flatpak-run +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-flatpak-run @@ -6,11 +6,11 @@ case ":${XDG_DATA_DIRS:-}:" in *"/flatpak/exports/share:"*) ;; *) export XDG_DATA_DIRS=$HOME/.local/share/flatpak/exports/share:${XDG_DATA_DIRS:-/usr/local/share:/usr/share} ;; esac -socket=() +options=() if [ -n "${DD_INSIDE:-}" ] || [ -n "${GAMESCOPE_WAYLAND_DISPLAY:-}" ]; then unset WAYLAND_DISPLAY export XDG_SESSION_TYPE=x11 - socket=(--nosocket=wayland --socket=x11) + options=(--nosocket=wayland --socket=x11) fi app= for arg in "$@"; do @@ -20,8 +20,15 @@ gpu=("${BASH_SOURCE[0]%/*}/droiddeck-game-gpu") location= [ -n "$app" ] && location=$(flatpak info --show-location "$app" 2>/dev/null) [ -n "$location" ] && gpu+=(--for "$location/files") -echo "== flatpak run ${socket[*]} $*" +filesystems= +[ -n "$location" ] && filesystems=$(flatpak info --show-permissions "$app" 2>/dev/null | sed -n 's/^filesystems=//p') +case ";$filesystems" in + *";home;"*|*";home:"*) ;; + *";host:ro;"*) options+=(--filesystem=home:ro) ;; + *";host;"*|*";host:"*) options+=(--filesystem=home) ;; +esac +echo "== flatpak run ${options[*]} $*" if [ -z "${DBUS_SESSION_BUS_ADDRESS:-}" ] && command -v dbus-run-session >/dev/null 2>&1; then - exec "${gpu[@]}" -- dbus-run-session -- flatpak run "${socket[@]}" "$@" + exec "${gpu[@]}" -- dbus-run-session -- flatpak run "${options[@]}" "$@" fi -exec "${gpu[@]}" -- flatpak run "${socket[@]}" "$@" +exec "${gpu[@]}" -- flatpak run "${options[@]}" "$@" diff --git a/tools/tests/test_game_gpu_launchers.py b/tools/tests/test_game_gpu_launchers.py index b4ddd3cbf4..6f4994e8c4 100644 --- a/tools/tests/test_game_gpu_launchers.py +++ b/tools/tests/test_game_gpu_launchers.py @@ -30,9 +30,16 @@ class GameGpuLaunchersTest(unittest.TestCase): % (" ".join(KEYS), self.out)) self.report.chmod(0o755) flatpak = self.tools / "flatpak" + self.permissions = self.tmp / "permissions" + self.args = self.tmp / "args" flatpak.write_text("#!/bin/sh\n" - "if [ \"$1\" = info ]; then [ \"$3\" = org.example.App ] && echo %s; exit 0; fi\n" - "exec %s\n" % (self.app, self.report)) + "if [ \"$1\" = info ]; then\n" + " [ \"$3\" = org.example.App ] || exit 0\n" + " if [ \"$2\" = --show-permissions ]; then cat %s 2>/dev/null; else echo %s; fi\n" + " exit 0\n" + "fi\n" + "printf '%%s\\n' \"$@\" > %s\n" + "exec %s\n" % (self.permissions, self.app, self.args, self.report)) flatpak.chmod(0o755) def chromium(self): @@ -100,6 +107,28 @@ class GameGpuLaunchersTest(unittest.TestCase): def test_a_flatpak_without_the_game_setting_is_unchanged(self): self.assertEqual("sysmem", self.flatpak({"TU_DEBUG": "sysmem"})["TU_DEBUG"]) + def flatpak_filesystems(self, granted): + self.permissions.write_text("[Context]\nshared=network;ipc;\nfilesystems=%s\n" % granted) + self.flatpak() + return [a for a in self.args.read_text().splitlines() if a.startswith("--filesystem=")] + + def test_host_access_reaches_the_home_folder_and_its_mounts(self): + self.assertEqual(["--filesystem=home:ro"], + self.flatpak_filesystems("host:ro;xdg-run/gamescope-0:ro;xdg-desktop:create;")) + self.assertEqual(["--filesystem=home"], self.flatpak_filesystems("xdg-desktop;host;")) + self.assertEqual(["--filesystem=home"], self.flatpak_filesystems("host:create;")) + + def test_apps_without_host_access_or_with_their_own_home_grant_are_unchanged(self): + self.assertEqual([], self.flatpak_filesystems("home:ro;host;")) + self.assertEqual([], self.flatpak_filesystems("host;home;")) + self.assertEqual([], self.flatpak_filesystems("host-os:ro;host-etc;xdg-download;")) + self.assertEqual([], self.flatpak_filesystems("")) + self.permissions.unlink() + self.flatpak() + args = self.args.read_text().splitlines() + self.assertEqual(["--command=app", "org.example.App"], args[-2:]) + self.assertFalse([a for a in args if a.startswith("--filesystem=")]) + def test_a_snap_gets_the_game_setting_unless_it_is_chromium(self): try: snap_run = runpy.run_path(str(BIN / "droiddeck-snap-run"))