cabal-flatpak
cabal-flatpak generates the files necessary for packaging a Haskell
application with Flatpak.
All the dependencies are explicitly pinned, in order to ensure reproducible
builds.
Usage
Generate the files
You need cabal-install 3.18.1.0 or later.
Run the command in your project:
$ cd /path/to/my-package
$ cabal build --dry-run --disable-tests --disable-benchmarks
$ cabal-flatpak generate --arch x86_64 --arch aarch64
The command reads the build plan that cabal computes
(dist-newstyle/cache/plan.json) and the .cabal file of your package.
The following files are then written in the project's root:
haskell-sources.yaml: Flatpak modules that build GHC
and all dependencies of your package
(and cabal-install, with --cabal-install).
<id>.yaml: a stub manifest for your application.
<id>.metainfo.xml: a stub MetaInfo file for Flathub.
<id>.desktop: a stub desktop entry.
The application ID <id> comes from the homepage field of the .cabal file.
For example, https://codeberg.org/haskell/cabal-flatpak
becomes page.codeberg.haskell.cabal-flatpak.
This works for GitHub, GitLab, Codeberg, Framagit and SourceForge.
For any other host, the ID is the reversed domain plus the package name
(https://xmonad.org becomes org.xmonad.<package>),
and the stub files have a FIXME comment.
Without a homepage, the ID is com.example.<package>.
Options
Files written
By default, both the stub manifest files and the dependencies file are written.
You should only need to generate the manifest once, only re-generate the
dependencies.
--dependencies: write haskell-sources.yaml only.
--manifest: write the stub files only.
--force: overwrite existing files.
Without it, the command skips them and prints a message.
--directory DIR: where the search for the project root starts.
The default is the current directory.
--local: build the application from the project directory.
The default is its Git repository.
The manifest gets a dir source with path: .,
which skips dist-newstyle and .flatpak-builder.
All generated files have .local before their extension,
for example haskell-sources.local.yaml and <id>.local.yaml.
Add *.local.* to .gitignore.
--icon FILE: the SVG or PNG icon that the manifest installs,
relative to the project root.
Without it, the manifest installs <id>.svg and has a FIXME comment.
--arch ARCH: an architecture to build for. Repeatable.
Usually only the ghc and cabal-install binaries depend on it.
--cabal-install: build all dependencies with cabal-install
in one module, haskell-deps (see below).
Each module builds its package with
runhaskell Setup build --jobs=$FLATPAK_BUILDER_N_JOBS.
Build the dependencies with cabal-install
By default each dependency is one Flatpak module,
and flatpak-builder builds them one after the other.
With --cabal-install the dependencies are in one module,
and cabal-install builds them in parallel.
Your package is built with cabal install.
$ cabal build --dry-run --disable-tests --disable-benchmarks
$ cabal-flatpak generate --cabal-install --dependencies --force
The haskell-deps module stores the build in /app/lib/cabal-store.
The stub manifest removes the store and the repository /app/lib/haskell-repo
from the final application:
cleanup:
- /lib/haskell-repo
- /lib/cabal-store/*/package.db
- /lib/cabal-store/*/*/lib
- /lib/cabal-store/*/*/bin
allow-newer and allow-older from cabal.project and cabal.project.local
go into the freeze file.
Version bound relaxations inside import: or if are not read yet,
you will have to add them by hand.
If one dependency changes, flatpak-builder will rebuild all of them,
because they are in one module.
Build the Flatpak package
Install the Flatpak runtime and its SDK:
$ sudo flatpak install org.freedesktop.Platform org.freedesktop.Sdk
Then build:
$ flatpak-builder --force-clean --repo=$FLATPAK/repository --state-dir=$FLATPAK/builder/ $FLATPAK/build/my-package <id>.yaml
Flatpak uses a lot of storage, so you may want $FLATPAK on a separate
partition.
--repo is your Flatpak repository, where flatpak-builder stores the result.
It holds all versions of all your Flatpak packages.
Anyone with access to it can install and update them.
--state-dir caches all downloads and build artifacts.
Projects can share it.
- The
DIRECTORY argument is where Flatpak builds your project.
Projects cannot share it. You can delete it after a build.
--force-clean deletes it at the start of the next build.
--state-dir and DIRECTORY must be on the same file system.
You can also export one version of your package to a single file,
for a one-time install (However, users of the bundle do not get updates).
$ flatpak build-bundle $FLATPAK/repository \
my-package-0.1.2.flatpak com.my_domain.my-package \
--runtime-repo=https://flathub.org/repo/flathub.flatpakrepo
Known issues
Cabal revisions
For reproducible builds, every module pins the revision of its
Haskell dependency, read from the pkg-revision field
of plan.json.
For this reason, cabal-install 3.18.1.0 or later is required.
Dependencies outside Hackage
Only Hackage dependencies are supported for now.
Contributions that add support for source-repository-package,
local tarball or remote tarball packages are welcome.
C dependencies
cabal-flatpak does not generate build instructions for C dependencies.
Write them yourself. flatpak-builder accepts a path to a module file
as an entry of modules.