menu

your app on all linuxes


Like me, you're probably thinking whyyy do i gotta learn this dumb thing? But until distros use flatpak, there's no choice.

FlatPak is well designed and well documented on
flatpak.org. Lemme summarize it first.

And flathub.org is how you distribute your app. It has picky requirements we'll get to.

End users actually install with a search and click in
KDE's discover app
gnome's software app


flatpak's main deal

is that your app links to a standard set of shared libs provided by a flatpak runtime - a standardized, versioned set of shared libs. You'll pick kde/gnome (Qt/GTK) and which version.


your app triplet

app names must not conflict - via an annoying reverse URL setup. My website is https://shaz.app and my app is pianocheetah so it must be named
app.shaz.pianocheetah

Not great. But, eh, not terrible.


permissions

Flatpak executables run in a sandbox. The idea is to protect users from malicious apps.

I don't understand that. If you don't trust it, why is it there?? Expecting permissions to prevent malicious apps is illogical.

In the end, your app must specify lots of permissions that all apps need. Yes my app uses graphics. Why? How could it not? Come on flatpak.


special directories

The sandbox gives your app standard "virtual" directories - all to itself. Executables are at:
/app/bin/whatev_app

And your config files are at:
/var/config/whatev.conf

These files are persisted in the user's home dir at:
/home/user/.var/app/app-triplet/etc-etc-etc

You can enter the sandbox to list and run stuff:
flatpak run --command=sh app.shaz.pianocheetah

 [app.shaz.pianocheetah app]$ cd /app/bin
 [app.shaz.pianocheetah bin]$ ls -al
 total 2128
 drwxr-xr-x 2 nfsnobody nfsnobody   4096 Dec 31  1969 .
 drwxr-xr-x 4 nfsnobody nfsnobody   4096 Oct 26 17:09 ..
 -rwxr-xr-x 2 nfsnobody nfsnobody 142640 Dec 31  1969 initme
 -rwxr-xr-x 2 nfsnobody nfsnobody  59584 Dec 31  1969 ll
 -rwxr-xr-x 2 nfsnobody nfsnobody 137248 Dec 31  1969 mid2song
 -rwxr-xr-x 2 nfsnobody nfsnobody 217504 Dec 31  1969 midicfg
 -rwxr-xr-x 2 nfsnobody nfsnobody  51288 Dec 31  1969 midimp
 -rwxr-xr-x 2 nfsnobody nfsnobody 101840 Dec 31  1969 mod2song
 -rwxr-xr-x 2 nfsnobody nfsnobody 947936 Dec 31  1969 pianocheetah
 -rwxr-xr-x 2 nfsnobody nfsnobody 118496 Dec 31  1969 sfz2syn
 -rwxr-xr-x 2 nfsnobody nfsnobody 171584 Dec 31  1969 song2wav
 -rwxr-xr-x 2 nfsnobody nfsnobody  97712 Dec 31  1969 synsnd
 -rwxr-xr-x 2 nfsnobody nfsnobody 110016 Dec 31  1969 txt2song
 [app.shaz.pianocheetah app]$ cd /var/config
 ...etc etc 

These directory paths only exist while the flatpak exes run. This will mean a minor rewrite to some of your code. If you start other executables that are part of the flatpak, you'll need to system() them in
/app/bin/whatever_exe

And when you write config files, them must be like
/var/config/my_conf.conf


Let's git started

First thing is your manifest. A json file that specs:
app triplet
which flatpak runtime (kde/gnome and which version)
your app permissions
how to find and build every executable

Here's mine. I use c++ and qt6. My app is still named app.pianocheetah.pianocheetah :/ I plan to rename it app.shaz.pianocheetah pretty soon.


permissions

are in finish-args. They'll be nearly the same for every app.
except no need for --socket=pulseaudio if you're not using audio
filesystem=home is preferred by flathub admins. But in practice this will turn paths in your home dir into ugly softlinks that I hate. Don't confuse my users. My preference is filesystem=host.


building

You give this to flatpak-builder (which you sudo apt install). I've put a script on top of it. Please excuse my php.

I have a common set of include files in a "stv" dir. Qt uses cmake-ninja which names your make file CMakeList.txt

My last module is the share dir within _fpak dir. With .desktop files, icon files, and a metainfo/app-triplet.metainfo.xml file about my program with screenshots, etc.

My script to actually run the build (please excuse my php) is here


distribute on flathub

You'll need a 2nd manifest for flathub. (unless you wanna always push your code and have your build script pull it).

Mine is here Note that it pulls from your public git repo with a certain commit hash so it stays frozen.

To submit your app to flathub, docs are here. Argh it's changed a little again. But you only "submit" once. You're given a repo to make a new branch on and add only your manifest. Then do a pull request on that repo and you're off to the races.

Reviewers will tell you your app does not meet spec. Work with them and be nice - I don't think they get paid. Once those guys do their thing, it shows up on flathub :) And eventually in KDE discover and Gnome software, too !!

Ok! That was some work but now your app is on linux nice and proper.

Some day I'll write up a thingy on Qt. But not today.

Go write some code :)


◤ home