cabal-flatpak: Generate FlatPak modules from a Cabal package description

[ bsd3, distribution, library, program ] [ Propose Tags ] [ Report a vulnerability ]

The generate command reads the build plan of a Cabal project and writes haskell-sources.yaml, a Flatpak module that builds GHC, cabal-install and every Hackage dependency without network access. It also writes a stub manifest, a MetaInfo file and a desktop file for a first Flathub submission. Inspired by Richard Szibele's stackpak: https://gitlab.com/rszibele/stackpak#readme


[Skip to Readme]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 0.0, 0.1, 0.1.0.1, 0.1.0.2, 0.1.0.3, 0.1.0.4, 0.1.1, 0.1.2, 0.1.3, 1.0.0
Change log CHANGELOG.md
Dependencies aeson (>=2.2.4.1 && <2.4), algebraic-graphs (>=0.7 && <0.9), base (>=4.22 && <5), base16-bytestring (>=1.0.2.0 && <1.1), bytestring (>=0.11.5.3 && <0.13), cabal-flatpak, Cabal-syntax (>=3.18.1 && <3.19), containers (>=0.6.8 && <0.9), directory (>=1.3.8.5 && <1.4), filepath (>=1.4.301.0 && <1.7), http-client (>=0.7.14 && <0.8), http-client-tls (>=0.3.5.3 && <0.5), http-types (>=0.11 && <0.13), JuicyPixels (>=3.3.8 && <3.4), nano-svg (>=0.2 && <0.3), network-uri (>=2.6.4.2 && <2.8), optparse-applicative (>=0.16.1.0 && <0.20), parsec (>=3.1.18.0 && <3.2), shell-utility (>=0.1 && <0.2), text (>=2.1.3 && <2.2), utility-ht (>=0.0.12 && <0.1), yamlet (>=1.0 && <1.1) [details]
Tested with ghc ==9.14.1
License BSD-3-Clause AND GPL-2.0-or-later[multiple license files]
Author Henning Thielemann <[email protected]>
Maintainer Hécate
Uploaded by hecate at 2026-11-27T13:25:50Z
Category Distribution
Home page https://codeberg.org/haskell/cabal-flatpak
Source repo head: git clone https://codeberg.org/haskell/cabal-flatpak
Distributions LTSHaskell:0.1.3, Stackage:0.1.3
Executables cabal-flatpak
Downloads 2291 total (81 in the last 30 days)
Rating 2.0 (votes: 1) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user
Build status unknown [no reports yet]

Readme for cabal-flatpak-1.0.0

[back to package description]

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.