Exploring the new Flatpak and Snap package formats
Rolling your Own Flatpak
Once Flatpak is installed and the flatpack
program is available, the developer creates an empty directory for a new flatpak:
flatpak build-init helloworld org.example. HelloWorld org.gnome.Sdk org.gnome.Platform 3.22
The individual parameters behind build-init
each have a special significance: helloworld
specifies the directory name within which the flatpak is created; org.example.HelloWorld
defines the D-bus name that the flatpak uses later to communicate with D-Bus. The SDK and the runtime, which the flatpak uses, are defined by org.gnome.Sdk
and org.gnome.Platform
, and 3.22
is the version number.
This example uses Gnome's SDK and runtime, which have been extensively tested and are fine for most everyday applications, but other options are also available.
The next step adds the program you wish to include in the flatpak. The flatpak build
command is very useful; the package builder uses it to execute arbitrary commands in the flatpak build environment. For example,
flatpak build helloworld touch /app/test
creates a test
file in the flatpak app
directory. You can also compile a program within Flatpak. First, download the sources [11] and unzip them. Next, type cd
to change to the folder with the unpacked sources; enter the following commands when you get there:
flatpak build flatpak_folder_name gcc $(pkg-config --cflags dbus-1 glib-2.0) -o send-hello dbus-send-hello.c $(pkg-config --libs dbus-1 glib-2.0)
flatpak_folder_name
is followed by the relative path to the directory just created by flatpak build-init
.
In the next step, you create the actual flatpak:
flatpak build-finish helloworld --socket=x11 --share=network --command=send-hello --socket=system-bus --socket=session-bus
The parameters --socket=x11
and --share=network
give the flatpak app access to X11 and the network, which is not necessary for this example but is for many applications.
In the next step, you can execute the flatpak with the help of the commands from Listing 1.
Listing 1
Running the Flatpak
The four commands create a Flatpak repository based on the local flatpak, add it to the Flatpak repository configuration, install the Flatpak from the repo, and finally execute it. The reward for all this effort is a Hello World message in the D-Bus logfile on the host system.
Powerful Tool
This example demonstrates only a tiny part of Flatpak's capability. The Flatpak website offers examples of how the package system can accommodate far more complex applications in a flatpak [12]. The granularity with which the developers have organized rights assignments is worthy of note. For each flatpak, the package maker determines whether the software needs access to X11, Wayland, D-Bus, or individual folders within the host filesystem. You can even control access to audio devices.
If you experiment with more complex Flatpak examples, you will also stumble across flatpak-builder
, which sounds a lot like flatpak-build
but is a separate tool. Flatpak-builder
accesses information from a JSON file that you created up front and builds a flatpak automatically.
The JSON file essentially contains the same information that you previously passed into flatpak-build
at the command line. The tool thus extends the principle to include a kind of batch mode, which proves to be very useful in practice (Figure 2).
![](/var/linux_magazin/storage/images/issues/2017/201/flatpak-and-snap/figure-2/707813-1-eng-US/Figure-21_large.png)
Exploring Snap
Unlike Flatpak, Snap is not targeted at desktop users. Canonical instead envisions Snap as a tool for revolutionizing the way enterprise applications reach servers. Like Flatpak, Snap relies on the kernel's various isolation techniques, combining them so applications run in their own isolated environments.
The structure of a snap is not fundamentally different from that of a flatpak, but the terms have different names. Instead of a runtime, Snap refers to a framework, which is a basic set of libraries on which Snap can build.
Unlike Flatpack, Snap is not aimed at general-purpose systems. Canonical is developing a basic system known as the Snappy Ubuntu Core [13] that offers different frameworks designed to work with the Snap package system (Figure 3).
![](/var/linux_magazin/storage/images/issues/2017/201/flatpak-and-snap/figure-3/707816-1-eng-US/Figure-31_large.png)
« Previous 1 2 3 4 Next »
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
![Learn More](https://www.linux-magazine.com/var/linux_magazin/storage/images/media/linux-magazine-eng-us/images/misc/learn-more/834592-1-eng-US/Learn-More_medium.png)
News
-
NVIDIA Released Driver for Upcoming NVIDIA 560 GPU for Linux
Not only has NVIDIA released the driver for its upcoming CPU series, it's the first release that defaults to using open-source GPU kernel modules.
-
OpenMandriva Lx 24.07 Released
If you’re into rolling release Linux distributions, OpenMandriva ROME has a new snapshot with a new kernel.
-
Kernel 6.10 Available for General Usage
Linus Torvalds has released the 6.10 kernel and it includes significant performance increases for Intel Core hybrid systems and more.
-
TUXEDO Computers Releases InfinityBook Pro 14 Gen9 Laptop
Sporting either AMD or Intel CPUs, the TUXEDO InfinityBook Pro 14 is an extremely compact, lightweight, sturdy powerhouse.
-
Google Extends Support for Linux Kernels Used for Android
Because the LTS Linux kernel releases are so important to Android, Google has decided to extend the support period beyond that offered by the kernel development team.
-
Linux Mint 22 Stable Delayed
If you're anxious about getting your hands on the stable release of Linux Mint 22, it looks as if you're going to have to wait a bit longer.
-
Nitrux 3.5.1 Available for Install
The latest version of the immutable, systemd-free distribution includes an updated kernel and NVIDIA driver.
-
Debian 12.6 Released with Plenty of Bug Fixes and Updates
The sixth update to Debian "Bookworm" is all about security mitigations and making adjustments for some "serious problems."
-
Canonical Offers 12-Year LTS for Open Source Docker Images
Canonical is expanding its LTS offering to reach beyond the DEB packages with a new distro-less Docker image.
-
Plasma Desktop 6.1 Released with Several Enhancements
If you're a fan of Plasma Desktop, you should be excited about this new point release.