Yes, you can take a non-Flatpak app and convert it into a Flatpak by compiling it from its source and packaging it into a Flatpak container, thanks to Flatpak's flexibility with non-Flatpak applications. The process involves compiling the app directly within the Flatpak build environment or within a compatible runtime by describing how to build and install it in the Flatpak manifest file (in .yml or .json format). This works for most open-source Linux apps, but you need the app's source code and some knowledge of its dependencies.
Let’s break this down!
How Flatpak Can Work for Non-Flatpak Apps
Flatpak does not require that the app is already "Flatpak-ready." Instead, Flatpak packages the app with all its dependencies into a sandbox for cross-distro compatibility.
- Non-Flatpak apps (e.g., a GitHub project, a tarball application, or proprietary apps like DaVinci Resolve when applicable) can be compiled from source during the Flatpak build process.
- Flatpak uses existing Linux development tools like make, cmake, ninja, and others that you set up in the application’s Flatpak manifest.
Steps You Will Take
- Download and/or compile the app source code.
- Package all necessary dependencies alongside the app into a Flatpak runtime.
- Optionally bundle the binaries or libraries (avoiding per-user compilation when using the prebuilt version).
How to Convert a Non-Flatpak App into a Flatpak
Below is a more detailed, step-by-step explanation of how to package a non-Flatpak app (like Nightingale) that has its source code.
Step 1: Gather the App’s Source Code
Most non-Flatpak apps provide their source code, often hosted on platforms like GitHub or GitLab.
For Nightingale, you might download its tarball or clone its source repository:
git clone https://github.com/nightingale-media-player/nightingale-hacking.git
cd nightingale-hacking
Make sure the source code is complete and includes a Makefile, configure script, or build instructions.
Step 2: Understand Dependencies
Check the application’s documentation (e.g., in a README.md or INSTALL file) to list its dependencies. For example, Nightingale lists several dependencies such as:
- GTK2 (GUI toolkit)
- GStreamer (audio and video playback)
- SQLite, TagLib, LibMad, and others.
You will need to specify these in the Flatpak manifest so the build process installs them in the Flatpak runtime.
Step 3: Choose a Suitable Flatpak Runtime
Flatpak requires a runtime to provide the base environment (system libraries, tools, etc.) for the app. Common runtime options include:
- org.freedesktop.Platform: For generic apps (GTK, CLI apps, etc.).
- org.gnome.Platform: For GNOME-based apps.
- org.kde.Platform: For KDE-based apps.
Nightingale likely requires org.freedesktop.Platform for its GTK and GStreamer dependencies.
Install the runtime locally:
flatpak install flathub org.freedesktop.Platform//22.08
flatpak install flathub org.freedesktop.Sdk//22.08
Step 4: Create a Flatpak Manifest
The manifest describes:
- How to fetch the app’s source code (e.g., via Git or a tarball URL).
- How to build the app (e.g., using commands like
./configure && make).
- Dependencies required (e.g., libraries Nightingale depends on).
Create a file called nightingale.yml:
nano nightingale.yml
Write the following YAML structure:
id: com.nightingale.Player
runtime: org.freedesktop.Platform
runtime-version: "22.08"
sdk: org.freedesktop.Sdk
command: nightingale
finish-args:
- --share=network
- --filesystem=host
modules:
- name: nightingale
buildsystem: simple
build-commands:
- ./configure --prefix=/app
- make -j$(nproc)
- make install
sources:
- type: archive
url: https://github.com/nightingale-media-player/nightingale-hacking/archive/master.tar.gz
sha256: <insert-correct-sha256>
Key Components:
- id: Unique application identifier (reverse DNS format).
- runtime and sdk: Defines the runtime environment used for dependencies and building.
- finish-args: Sandboxing permissions (e.g., filesystem and network access).
- modules:
- Specifies what to build, how to build it (
build-commands), and where to download the source (sources).
To get the sha256 checksum, download the source tarball and compute:
sha256sum master.tar.gz
Step 5: Build the Flatpak
Use flatpak-builder to compile the source code and package the app as a Flatpak.
-
Create a temporary build directory:
mkdir build-dir
-
Build the Flatpak:
flatpak-builder --force-clean build-dir nightingale.yml
This will:
- Fetch the source code from the repository.
- Install build dependencies in the Flatpak runtime.
- Compile the source code using the build commands from the manifest.
- Package the compiled app into a sandboxed Flatpak.
Step 6: Test the Flatpak
You can test the Flatpak directly without installing it globally:
flatpak-builder --run build-dir nightingale.yml nightingale
If the app runs successfully, you’re ready to distribute or locally install it.
Step 7: Install or Distribute Your Flatpak
-
Install locally:
flatpak-builder --repo=repo --force-clean build-dir nightingale.yml
flatpak build-bundle repo nightingale.flatpak com.nightingale.Player
flatpak install nightingale.flatpak
-
Distribute the app to others:
- Host the repository (
repo) or the Flatpak bundle (.flatpak) on a server.
- Share it with users, who can add the repository or download the
.flatpak file.
Additional Tips
-
Using Precompiled Binaries Instead of Compiling:
If the app provides a prebuilt binary (e.g., .deb, .AppImage, or tarball), you can package that into a Flatpak instead of compiling. Replace build-commands in the manifest with commands to unpack and copy the binary to /app.
-
Debugging:
Use flatpak-builder's --sandbox or --disable-sandbox options to debug build errors.
-
Packaging for Flathub:
Submit your app to Flathub (Flatpak's repository) by following their contribution guide.
Conclusion
Yes, you can take any Linux-compatible app, even if it’s not in Flatpak format, and compile/package it as a Flatpak. While the process may require some trial and error (especially for handling dependencies), once complete, your app will be portable, sandboxed, and ready to use across many distributions.
If you'd like help with a specific app or debugging a manifest, feel free to ask! 🚀