For my app, I need to read the host’s XDG_DATA_DIRS var.
Well really, I want to read the host desktop entries detected shown in the overview.
I know that I can read the exposed host filesystem with --filesystem=root so I ultimately could read almost any directory.
The problem is really, how to get which directories to read ? This is given (partially) by XDG_DATA_DIRS.
Would there be a way to access the host environment variables, maybe like we can mount / to /var/run/host copy XDG_DATA_DIRS to HOST_XDG_DATA_DIRS ?
There is a flatpak-spawn command available for every flatpak app which lets you run random commands on the host as long as you have --talk-name=org.freedesktop.Flatpak permission.
You could run the following command inside the flatpak.
flatpak-spawn --host sh -c 'echo $XDG_DATA_DIRS'
This will get you what you want.
This is NOT recommended though.
Reasons
Not all systems have XDG_DATA_DIRS set.
Even if XDG_DATA_DIRS is set, its values do not get translated to their /var/run/host equivalents. That is if the host has XDG_DATA_DIRS=~/.local/share:/usr/local/share:/usr/share, what you require is XDG_DATA_DIRS=~/.local/share:/var/run/host/usr/local/share:/var/run/host/usr/share
If you want your app on Flathub, they won’t allow permissions like --filesystem=host or --filesystem=/, etc. anyway.
However you’re right, it’s a bad idea and a security concern to give so much permission, I will not use it.
Until we have a better option,the flatpak build will not include the “Desktop entries” source, but the native package will.
I realize that I fell into the A/B problem with my title, what I really need is a list of desktop entries and their content. I’m working on Gali, a game library viewer and launcher whose aim is to aggregate all the games present on a system in one place. Thus, I need desktop entries to list standalone games.
After talking with Emmanuele Bassi and Alexander Mikhaylenko on Matrix I’ve opened a new portal request Desktop entries / App list portal #809 on the xdg-desktop-portal repo.