flatpak
, GTK
, pywebview
, HTTP server
, python
, bottle
This includes examples to package applications as flatpak apps.
Previous lightning talk: Package a PyApp as a Flatpak Package: An HTTP Server for Example
Some flatpak's security discussion:
Some major Linux distributions, like Fodora, openSUSU and Endless OS have already pre-installed flatpak. Please follow Flathub's setup for your OS distribution. If it is not installed, basically install it like:
apt install flatpak flatpak-builder
yum install flatpak flatpak-builder
dnf install flatpak flatpak-builder
pacman -S flatpak flatpak-builder
apk add flatpak flatpak-builder
Then, add the Flathub repository
flatpak remote-add --if-not-exists flathub https://dl.flathub.org/repo/flathub.flatpakrepo
The flatpak is for common usage, and flatpak-builder is for packaging as a flatpak package. Not only x86(_64) platforms, but also arm64 and so on β¦
The org.freedesktop.Sdk
runtime commands for developing, like sh & echo, compiler gcc, and python & pip.
$ flatpak run --command=sh org.freedesktop.Sdk//23.08
[π¦ org.freedesktop.Sdk ~]$ ls -l /bin/{sh,echo,gcc,python,pip}
-rwxr-xr-x 5 nfsnobody nfsnobody 45736 Jan 1 1970 /bin/echo
lrwxrwxrwx 1 nfsnobody nfsnobody 28 Nov 5 18:44 /bin/gcc -> x86_64-unknown-linux-gnu-gcc
-rwxr-xr-x 7 nfsnobody nfsnobody 220 Jan 1 1970 /bin/pip
lrwxrwxrwx 1 nfsnobody nfsnobody 16 Nov 5 18:44 /bin/python -> /usr/bin/python3
lrwxrwxrwx 1 nfsnobody nfsnobody 4 Nov 5 18:44 /bin/sh -> bash
The org.freedesktop.Platform
runtime has commands for common usage, like sh & echo and python. But, no development tools.
$ flatpak run --command=sh org.freedesktop.Platform//23.08
[π¦ org.freedesktop.Platform ~]$ ls -l /bin/{sh,echo,gcc,python,pip}
ls: cannot access '/bin/gcc': No such file or directory
ls: cannot access '/bin/pip': No such file or directory
-rwxr-xr-x 5 nfsnobody nfsnobody 45736 Jan 1 1970 /bin/echo
lrwxrwxrwx 1 nfsnobody nfsnobody 16 Oct 31 20:34 /bin/python -> /usr/bin/python3
lrwxrwxrwx 1 nfsnobody nfsnobody 4 Oct 31 20:34 /bin/sh -> bash
PS. More well-known runtimes in Available Runtimes.
.flatpakref
from Flathub website:.flatpakref
:
ββflatpak install <Application ID>.flatpakref
ββflatpak install [flathub] <Application ID>
ββflatpak run <Application ID>
ββflatpak uninstall [--delete-data] <Application ID>
run.sh
:
βββ$ cat run.sh
βββ#!/bin/sh
βββecho "Hello world!"
io.github.starnight.simpledemo.yml
for build:
βββ$ cat io.github.starnight.simpledemo.yml
βββapp-id: io.github.starnight.simpledemo
βββruntime: org.freedesktop.Platform
βββruntime-version: '23.08'
βββsdk: org.freedesktop.Sdk
βββcommand: run.sh
βββmodules:
βββ - name: simpledemo
βββ buildsystem: simple
βββ build-commands:
βββ - install -D run.sh /app/bin/run.sh
βββ sources:
βββ - type: file
βββ path: run.sh
βββflatpak install flathub org.freedesktop.Sdk//23.08
io.github.starnight.simpledemo
as a flatpak app, and install it:
βββflatpak-builder build-dir io.github.starnight.simpledemo.yml --force-clean --install --user
io.github.starnight.simpledemo
is installed:
βββ$ flatpak list
βββName Application ID Version Branch Origin Installation
βββsimpledemo io.github.starnight.simpledemo master simpledemo-origin user
βββ...
βββFreedesktop Platform org.freedesktop.Platform 23.08.6 23.08 flathub system
βββ...
βββFreedesktop SDK org.freedesktop.Sdk 23.08.6 23.08 flathub system
βββ...
io.github.starnight.simpledemo
flatpak app
βββ$ flatpak info io.github.starnight.simpledemo
βββ ID: io.github.starnight.simpledemo
βββ Ref: app/io.github.starnight.simpledemo/x86_64/master
βββ Arch: x86_64
βββ Branch: master
βββ Origin: simpledemo-origin
βββ Collection:
βββInstallation: user
βββ Installed: 2.0 kB
βββ Runtime: org.freedesktop.Platform/x86_64/23.08
βββ Sdk: org.freedesktop.Sdk/x86_64/23.08
βββ Commit: badf1daffd1f6ec3b4d3ca35bab60b4beecb15b22e7b3dc8fa041609d8913040
βββ Subject: Export io.github.starnight.simpledemo
βββ Date: 2023-11-05 14:37:17 +0000
βββ$ flatpak run --command=ls io.github.starnight.simpledemo /app/bin
βββrun.sh
βββ$ flatpak run io.github.starnight.simpledemo
βββHello world!
βββgit clone https://github.com/starnight/flatpak-example-gtkdemo
βββ$ flatpak run --command=sh org.gnome.Sdk//45
βββ[π¦ org.gnome.Sdk ~]$ ls -l /lib/x86_64-linux-gnu/libgtk-4*
βββlrwxrwxrwx 1 nfsnobody nfsnobody 13 Oct 31 20:34 /lib/x86_64-linux-gnu/libgtk-4.so -> libgtk-4.so.1
βββlrwxrwxrwx 1 nfsnobody nfsnobody 20 Oct 31 20:34 /lib/x86_64-linux-gnu/libgtk-4.so.1 -> libgtk-4.so.1.1200.3
βββ-rwxr-xr-x 3 nfsnobody nfsnobody 8999080 Jan 1 1970 /lib/x86_64-linux-gnu/libgtk-4.so.1.1200.3
βββgit clone https://github.com/starnight/flatpak-example-pywebview
Because this example is written in Python and uses pywebview, which depends on bottle β¦, and more. The dependecies heads are listed in requirements.txt. The dependencies, like pywebview and bottle β¦ must be installed as part of the flatpak app as well. So, we need flatpak-builder-tools's flatpak-pip-generator to generate the required modulesβ meta information for the manifest from requirements.txt.
$ git clone https://github.com/flatpak/flatpak-builder-tools
$ python3 ~/flatpak-builder-tools/pip/flatpak-pip-generator --requirements-file=requirements.txt
The required modulesβ meta information is generated & saved as python3-requirements.json in Build's step 3. Then, python3-requirements.json is invoked as a module by the flatpak's manifest.
PS. flatpak-builder-tools depends on requirements-parser
According to Freedesktop.org Specifications:
<application ID>.dekstop
. The desktop launcher should be saved under path $XDG_DATA_DIRS/applications
.$XDG_DATA_DIRS/icons
.Because this flatpak demo is in user installations, the desktop launcher and the icon in the flatpak are exported into user's ~/.local/share/flatpak/exports/share
:
$ echo $XDG_DATA_DIRS
/home/zack/.local/share/flatpak/exports/share:/var/lib/flatpak/exports/share:/usr/local/share/:/usr/share/
$ ls -l ~/.local/share/flatpak/exports/share/applications/io.github.starnight.http.desktop
lrwxrwxrwx 1 zack zack 111 Nov 10 22:16 /home/zack/.local/share/flatpak/exports/share/applications/io.github.starnight.http.desktop -> ../../../app/io.github.starnight.http/current/active/export/share/applications/io.github.starnight.http.desktop
$ ls -l ~/.local/share/flatpak/exports/share/icons/hicolor/scalable/apps/io.github.starnight.http.svg
lrwxrwxrwx 1 zack zack 131 Nov 10 22:16 /home/zack/.local/share/flatpak/exports/share/icons/hicolor/scalable/apps/io.github.starnight.http.svg -> ../../../../../../app/io.github.starnight.http/current/active/export/share/icons/hicolor/scalable/apps/io.github.starnight.http.svg
According to flatpak-installation:
$prefix/var/lib/flatpak/
βββ$ flatpak info --show-location org.gnome.gedit
βββ/var/lib/flatpak/app/org.gnome.gedit/x86_64/stable/09a23c12f530b56b84db84dc8cbc24d949f352e154c1a5aef5cdaaf3df2f573c
$HOME/.local/share/flatpak/
βββ$ flatpak info --show-location io.github.starnight.http
βββ/home/zack/.local/share/flatpak/app/io.github.starnight.http/x86_64/master/e44f532e79374461e4e3c32db5f11ef75c1a7dee03fa7634c64a46c88dff5f19
Flathub's For app authors:
Flatpak app builds with external data (git checkouts, tarballs, simple files, etc.) listed as modules in the manifest. Maintaining the external data's source/link is important. Flatpak External Data Checker is a tool to create pull requests to the repository on GitHub automatically, if there is new version of the external data's source/link.
"x-checker-data"
into each modules of the manifestWill Thompson shared a talk: "Automate your Flatpak manifest updates today"
Learn More β
The WebView Demo uses Flatpak External Data Checker to update the dependencies:
x-checker-data
section as an exampleThis is more related to the original application, because it should come from there. However, Flathub reads the application's metainfo, then renders the introduction on Flathub. And, Software/App Center does the same thing.
Cassidy James Blaede shared a talk: "How to make a delightful app listing"
Learn More β
Note: The talk starts at 12 minute of the video.