Bug 401956

Summary: Flatpak can't interoperate with hosts packages data
Product: [Applications] Discover Reporter: Andrey <butirsky>
Component: discoverAssignee: Aleix Pol <aleixpol>
Status: RESOLVED FIXED    
Severity: normal CC: aleixpol
Priority: NOR    
Version First Reported In: unspecified   
Target Milestone: ---   
Platform: Flatpak   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:

Description Andrey 2018-12-10 13:38:30 UTC
As usual Flatpak container, Discover being packaged with Flatpak has separate from host data directory. This mean it can't interoperate with hosts installed packages, etc.
The problem is XDG_DATA_HOME environment variable.
By default, is has value <$HOME>/.var/app/org.kde.discover/data.
To make it work, I have to manually change it's value in the container before Discover run:

$ flatpak run --command=sh org.kde.discover
$ export XDG_DATA_HOME=~/.local/share/
$ plasma-discover

I didn't find any solution beside hardcode the variable value at build time.
Any suggestions are welcome, but I think we should fix it any way.
Comment 1 Andrey 2018-12-10 17:35:16 UTC
 --env doesn't override XDG_DATA_HOME:

https://github.com/flatpak/flatpak/issues/2413
Comment 2 Aleix Pol 2018-12-11 01:04:18 UTC
Git commit 352e9f49cc59c5c0ce3e03e03a193f384196e1ef by Aleix Pol.
Committed on 11/12/2018 at 01:04.
Pushed by apol into branch 'master'.

discover: fix listing user's flatpak apps

Includes a wrapper that overrides the modified XDG_DATA_HOME.

A  +3    -0    discover/wrapper.sh
M  +10   -2    org.kde.discover.json

https://commits.kde.org/flatpak-kde-applications/352e9f49cc59c5c0ce3e03e03a193f384196e1ef
Comment 3 Aleix Pol 2018-12-11 01:04:57 UTC
You will have to be a bit patient for the fix to land into the binaries, because we have some issues with flathub's builds.
Comment 4 Andrey 2018-12-11 09:40:18 UTC
Thanks Aleix for providing the wrapper.
But, in the common case, I have to say it will not work - the user's host XDG_DATA_HOME doesn't have to be ~/.local/share/.
So proper fix seems to be on Flatpak side, but they just closed my issue on github above. So I really don't know what to do..
Comment 5 Aleix Pol 2018-12-11 12:16:59 UTC
I'd say try to get it to work for you and we can iterate as it evolves, fixing one issue at a time.
Comment 6 Andrey 2018-12-11 15:46:03 UTC
Ok, you are the boss :)
The wrapper works for me, thank you.
Just a little improvement - no need to add a separate file, this would look more convenient(sorry, don't know how to paste code):

"sources": [
    { "type": "git", "url": "git://anongit.kde.org/discover.git" },
    {
            "type": "script",
            "dest-filename": "discoverwrapper.sh",
            "commands": [ "XDG_DATA_HOME=~/.local/share plasma-discover" ]
    }
],
"post-install": [ "cp ../discoverwrapper.sh /app/bin/" ],

Can we iterate now? :)
Comment 7 Aleix Pol 2018-12-11 16:28:06 UTC
Sure, can you please provide it into a phabricator.kde.org patch?
Comment 8 Andrey 2018-12-11 17:21:14 UTC
uff, all these phabricator things are hard to me. I would need time to learn it first
Comment 9 Andrey 2018-12-11 21:27:44 UTC
Maybe we should set FLATPAK_USER_DIR here instead of XDG_DATA_HOME - perhaps, it more precisely reflects our needs:

FLATPAK_USER_DIR
     The location of the per-user installation. If this is not set, $XDG_DATA_HOME/flatpak is used. 

http://docs.flatpak.org/en/latest/search.html?q=FLATPAK_USER_DIR
Comment 10 Christoph Feck 2019-01-09 02:29:11 UTC
There is not much to learn. Log in, visit https://phabricator.kde.org/differential/diff/create/ and paste your diff there (or load from file). The only thing you need to remember is to set "Repository" to "Discover".
Comment 11 Andrey 2019-01-09 02:54:26 UTC
(In reply to Christoph Feck from comment #10)
> There is not much to learn. 
Christoph, the was a lot to learn eventually!
Phabricator turned out to be a mess when working with patchsets. Things are over-complicated and needed functionality absent. I really disappointed.