You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Discussion] Possibilities to add support to install / uninstall / updates Flatpak apps from another Flatpak sandbox #4046
During the development we tried to figure out, what's the best way for installing / uninstalling / updating Flatpak applications from a Flatpak sandbox. We stumbled over following ideas:
1. Bundle (lib)flatpak with the application itself, and write directly to the ostree repository.
This approach only works for writing to user installations. Writing directly to the system installation is not possible, since it need further privileges / polkit authorizations to access the system installation. Since everything defaults to system at the moment, this won't work. We don't want to limit Souk to user based stuff only.
2. Using (lib)flatpak only to read information from installations, and use Flatpak CLI for writing actions.
That's how we're currently installing / uninstalling stuff in Souk. We're calling the hostside flatpak CLI by using flatpak-spawn --host, and for reading information we're using libflatpak. This kinda works, but feels pretty hackish. When Flatpak decides to change its CLI interface, Souk will break completely.
To prevent such breakages in future, we're wondering what we could do to prevent it. As I see there's currently no proper way for solving this problem, beside installing the store application itself as non-flatpak application. Maybe we can use this issue to discuss about potential solutions for the future. For example, maybe a DBUS portal could work, which talks to the hostside flatpak?
Reacted by Chris, Ivan Molodetskikh, Maarten de Jong, Bilal Elmoussaoui, Martin Zilz, Tobias Bernard, Felix Häcker, Chetan Khilosiya, Jonas Dreßler, Zander and 17 more
I talked a bit with @matthiasclasen on the Flatpak IRC room, and have to agree it's not realistic to make the whole API of libflatpak available per dbus / a portal.
I think it would be okay to mark as duplicate of #4046 so long as we are allowing support for choosing which installation (and optionally providing a path) to the installation necessary. Another possibility would be for it to install using any installation, but provide paths to additional installations to check.
So I'll close that issue and when this is implemented we can use the implementation ideas there for it, as well as the custom installation requirement.
Small update - I think I have found another 3rd option. Also not completely without tricks / hacks, but I think this is by far the best method.
Libflatpak is bundled inside the Flatpak sandbox and also works inside the sandbox. To make privileged (system-wide) changes, the following changes are necessary:
Enable --system-talk-name=org.freedesktop.PolicyKit1 so libflatpak can ask system polkit for permissions
The actual privileged (root) operations are not performed from the sandbox, but by the Flatpak flatpak-system-helper daemon running on the host system. To communicate with it, the --system-talk-name=org.freedesktop.Flatpak.SystemHelper permission is required.
To access the system repository (readonly), the --filesystem=/var/lib/flatpak/ permission is required (actual write access is performed via the flatpak-system-helper host daemon).
This was relatively "easy" since the actual operations on the host side are performed by the flatpak-system-helper daemon. Ironically, the user related operations were more difficult, since there is no daemon on the host side to perform the operations. The following changes were necessary:
The installation must be created manually with flatpak_installation_new_for_path(), because flatpak_installation_new_user() would point to /home/<username>/.var/app/<appid>/data/flatpak/repo/.
In the sandbox, flatpak-bwrap cannot be executed. This must be forwarded to the host system with the appropriate file descriptors. In Souk's example I solved this with a wrapper script (not very nice, but gets the job done). This is not strictly required, but for some apps with extra_data, e.g. Spotify, this is needed as flatpak-bwrap would be executed during installation.
The FLATPAK_BINARY=/usr/bin/flatpak environment variable must be set, otherwise the flatpak path in the exported desktop files would be wrong.
With this method, both system and user operations can be performed from a Flatpak Sandbox, without executing Flatpak commands with flatpak-spawn --host, and parsing its output manually (idea 2 in the first message above).
CC: @chergert you may be interested in this, as far as I know Builder currently has no way to install SDKs system wide, and is limited to the user installation.
I have implemented this option as a proof-of-concept in Souk, from the tests I have done, it seems to work without problems:
To access the system repository (readonly), the --filesystem=/var/lib/flatpak/ permission is required (actual write access is performed via the flatpak-system-helper host daemon).
Wouldn't you need --filesystem=/var/lib/flatpak:ro to make the access read only?
@mwleeds ah yes, you're right. Though I think it wouldn't even make a difference if it was explicitly stated, since the Flatpak sandbox wouldn't have write access to the directory anyway.
RetroDECK: retrodeck inside flatpak needs a way to launch other flatpak'ed emulators, right now retrodeck's flatpak bundles ALL emulators it can use, which is results in ~2.53 GB installed size.
Reacted by JakobDev, Mr Beedell, Roke Julian Lockhart, rugk, Teoh Han Hui, Newbyte, Maarten de Jong, Felicitas Pojtinger, bmsuseluda, Nutjob, rvbg and 10 more
FWIW, FreeCAD abuses1flatpak-spawn to launch OpenSCAD as a command-line converter, and does this using the flatpak. With all the caveats, like it will fail if the flatpak isn't installed.
Activity
mwleeds commentedon Jan 8, 2021
The work in #3322 may be relevant.
haecker-felix commentedon Jan 8, 2021
In theory a portal would work, unfortunately #3322 is currently limited to install only extensions of applications.
haecker-felix commentedon Feb 18, 2021
I talked a bit with @matthiasclasen on the Flatpak IRC room, and have to agree it's not realistic to make the whole API of libflatpak available per dbus / a portal.
mwleeds commentedon Oct 8, 2021
Quoting from #4437:
So I'll close that issue and when this is implemented we can use the implementation ideas there for it, as well as the custom installation requirement.
soredake commentedon Jun 19, 2022
Also flatpak/xdg-desktop-portal#283
haecker-felix commentedon Jun 26, 2022
Small update - I think I have found another 3rd option. Also not completely without tricks / hacks, but I think this is by far the best method.
Libflatpak is bundled inside the Flatpak sandbox and also works inside the sandbox. To make privileged (system-wide) changes, the following changes are necessary:
--system-talk-name=org.freedesktop.PolicyKit1so libflatpak can ask system polkit for permissionsflatpak-system-helperdaemon running on the host system. To communicate with it, the--system-talk-name=org.freedesktop.Flatpak.SystemHelperpermission is required.--filesystem=/var/lib/flatpak/permission is required (actual write access is performed via theflatpak-system-helperhost daemon).This was relatively "easy" since the actual operations on the host side are performed by the
flatpak-system-helperdaemon. Ironically, theuserrelated operations were more difficult, since there is no daemon on the host side to perform the operations. The following changes were necessary:flatpak_installation_new_for_path(), becauseflatpak_installation_new_user()would point to/home/<username>/.var/app/<appid>/data/flatpak/repo/.flatpak-bwrapcannot be executed. This must be forwarded to the host system with the appropriate file descriptors. In Souk's example I solved this with a wrapper script (not very nice, but gets the job done). This is not strictly required, but for some apps with extra_data, e.g. Spotify, this is needed asflatpak-bwrapwould be executed during installation.FLATPAK_BINARY=/usr/bin/flatpakenvironment variable must be set, otherwise theflatpakpath in the exported desktop files would be wrong.With this method, both
systemanduseroperations can be performed from a Flatpak Sandbox, without executing Flatpak commands withflatpak-spawn --host, and parsing its output manually (idea 2 in the first message above).CC: @chergert you may be interested in this, as far as I know Builder currently has no way to install SDKs system wide, and is limited to the
userinstallation.I have implemented this option as a proof-of-concept in Souk, from the tests I have done, it seems to work without problems:
Screencast_from_26-06-22_16.05.41.mp4
The code is available at: https://gitlab.gnome.org/haecker-felix/souk/-/tree/souk-next
I am open to feedback / thoughts!
mwleeds commentedon Jun 27, 2022
Wouldn't you need
--filesystem=/var/lib/flatpak:roto make the access read only?haecker-felix commentedon Jun 27, 2022
@mwleeds ah yes, you're right. Though I think it wouldn't even make a difference if it was explicitly stated, since the Flatpak sandbox wouldn't have write access to the directory anyway.
soredake commentedon Jul 7, 2022
Example of the apps that needs this functinality:
Right now this software uses/will use
flatpak-spawn --host:Actually there are MANY flatpak's that use
flatpak-spawn --hosthttps://github.com/search?p=1&q=org%3Aflathub+org.freedesktop.Flatpak&type=Codehfiguiere commentedon Aug 20, 2022
FWIW, FreeCAD abuses1
flatpak-spawnto launch OpenSCAD as a command-line converter, and does this using the flatpak. With all the caveats, like it will fail if the flatpak isn't installed.Footnotes
I did the work, I own it. ↩