Stackpak - Flatpak a Haskell Stack App into Flathub

31 August 2018 01:46 GMT

After reading David Lettier's great post on How to Flatpak a Haskell App into Flathub, I thought about generalizing his approach for Haskell stack projects and have written stackpak.

How Stackpak works

It's quite simple: you give stackpak a base Flatpak manifest on how to build only your Haskell project and the path to your projects' directory and stackpak spits out a new Flatpak manifest with all Haskell dependencies included.

You would accomplish that by running the following command after installing stackpak:

$ stackpak --output=my-new-manifest.json /path/to/base-manifest.json /path/to/stack-project
To be able to generate your manifest for you, stackpak does the following:
  1. reads your projects stack.yaml
  2. reads your projects package.yaml
  3. reads the corresponding lts-xx.xx.yaml
  4. determines the latest commit for github.com/commercialhaskell/all-cabal-files
  5. downloads ghc for all architectures and generates their hashes (i386, x86_64, arm, aarch64)
  6. determines the build order of your projects dependencies
  7. downloads the latest cabal manifest files and generates their hashes
  8. and finally merges your base Flatpak manifest with the generated manifest and saves it to disk
A few things to note:
  1. all ghc architectures are downloaded so that Flatpak can build on all architectures
  2. there is no easy way to download the latest cabal manifest from Hackage, that's why we need to fetch it from the github repository

Base Flatpak Manifest

So what does a base Flatpak manifest for stackpak look like?

{
    "app-id": "com.mysite.myapp",
    "runtime": "org.freedesktop.Platform",
    "runtime-version": "1.6",
    "sdk": "org.freedesktop.Sdk",
    "command": "my-haskell-exe",
    "finish-args": [],
    "cleanup": [],
    "cleanup-commands": [],
    "modules": [
        {
            "name": "my-haskell-exe",
            "only-arches": [],
            "buildsystem": "simple",
            "builddir": true,
            "build-commands": [
                "ghc -threaded --make Setup",
                "./Setup configure --prefix=/app",
                "./Setup build",
                "./Setup install"
            ],
            "cleanup": [],
            "cleanup-commands": [],
            "sources": [
                {
                    "type": "archive",
                    "url": "https://gitlab.com/myusername/myapp/-/archive/1.0.0/myapp-1.0.0.tar.gz",
                    "sha256": "4c4176d77d25e51df686bc1c30fa774e25132e45b787f3ce377ad92cd4562a2f"
                }
            ]
        }
    ]
}

Example Project using Stackpak

An example project using stackpak is e-juice-calc, a calculator which allows you to calculate a recipe for mixing your own e-liquids.
Check out the base Flatpak manifest of E-Jucie-Calc and the generated Flatpak manifest

Copyright © Richard Szibele. All rights reserved.