Skip to content

Fix flatpak packaging to a working state #6678

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Apr 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 57 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ jobs:
- build-macos-matrix
- build-windows
- build-windows-cross
- flatpak-check-zig-cache
- flatpak
- test
- test-gtk
- test-sentry-linux
Expand Down Expand Up @@ -734,7 +736,7 @@ jobs:

translations:
if: github.repository == 'ghostty-org/ghostty'
runs-on: namespace-profile-ghostty-sm
runs-on: namespace-profile-ghostty-xsm
timeout-minutes: 60
env:
ZIG_LOCAL_CACHE_DIR: /zig/local-cache
Expand All @@ -761,7 +763,7 @@ jobs:

blueprint-compiler:
if: github.repository == 'ghostty-org/ghostty'
runs-on: namespace-profile-ghostty-sm
runs-on: namespace-profile-ghostty-xsm
timeout-minutes: 60
env:
ZIG_LOCAL_CACHE_DIR: /zig/local-cache
Expand Down Expand Up @@ -851,3 +853,56 @@ jobs:
file: dist/src/build/docker/debian/Dockerfile
build-args: |
DISTRO_VERSION=12
flatpak-check-zig-cache:
if: github.repository == 'ghostty-org/ghostty'
runs-on: namespace-profile-ghostty-xsm
env:
ZIG_LOCAL_CACHE_DIR: /zig/local-cache
ZIG_GLOBAL_CACHE_DIR: /zig/global-cache
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Cache
uses: namespacelabs/[email protected]
with:
path: |
/nix
/zig
- name: Setup Nix
uses: cachix/install-nix-action@v30
with:
nix_path: nixpkgs=channel:nixos-unstable
- uses: cachix/cachix-action@v15
with:
name: ghostty
authToken: "${{ secrets.CACHIX_AUTH_TOKEN }}"
useDaemon: false # sometimes fails on short jobs
- name: Check Flatpak Zig Dependencies
run: nix develop -c ./flatpak/build-support/check-zig-cache.sh

flatpak:
if: github.repository == 'ghostty-org/ghostty'
name: "Flatpak"
container:
image: ghcr.io/flathub-infra/flatpak-github-actions:gnome-47
options: --privileged
strategy:
fail-fast: false
matrix:
variant:
- arch: x86_64
runner: namespace-profile-ghostty-md
- arch: aarch64
runner: namespace-profile-ghostty-md-arm64
runs-on: ${{ matrix.variant.runner }}
needs: [flatpak-check-zig-cache, test]
steps:
- uses: actions/checkout@v4
- uses: flatpak/flatpak-github-actions/flatpak-builder@v6
with:
bundle: com.mitchellh.ghostty
manifest-path: flatpak/com.mitchellh.ghostty.yml
cache-key: flatpak-builder-${{ github.sha }}
arch: ${{ matrix.variant.arch }}
verbose: true
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ zig-out/
example/*.wasm
test/ghostty
test/cases/**/*.actual.png
flatpak/builddir/
flatpak/repo/

glad.zip
/Box_test.ppm
Expand Down
59 changes: 0 additions & 59 deletions com.mitchellh.ghostty.yml

This file was deleted.

59 changes: 59 additions & 0 deletions dist/linux/com.mitchellh.ghostty.metainfo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8"?>
<component type="desktop-application">
<id>com.mitchellh.ghostty</id>
<launchable type="desktop-id">com.mitchellh.ghostty.desktop</launchable>
<name>Ghostty</name>
<url type="homepage">https://ghostty.org</url>
<url type="help">https://ghostty.org/docs</url>
<url type="bugtracker">https://github.com/ghostty-org/ghostty/discussions</url>
<url type="contact">https://ghostty.org/docs/help</url>
<url type="contribute">https://github.com/ghostty-org/ghostty/blob/main/CONTRIBUTING.md</url>
<url type="translate">https://github.com/ghostty-org/ghostty/blob/main/po/README_TRANSLATORS.md</url>
<url type="vcs-browser">https://github.com/ghostty-org/ghostty</url>
<summary>Ghostty is a fast, feature-rich, and cross-platform terminal emulator</summary>
<metadata_license>MIT</metadata_license>
<project_license>MIT</project_license>
<content_rating type="oars-1.1" />
<developer id="com.mitchellh">
<name>Mitchell Hashimoto</name>
</developer>
<update_contact>[email protected]</update_contact>
<description>
<p>
Ghostty is a terminal emulator that differentiates itself by being fast,
feature-rich, and native. While there are many excellent terminal
emulators available, they all force you to choose between speed,
features, or native UIs. Ghostty provides all three.
</p>
</description>
<recommends>
<control>keyboard</control>
<control>pointing</control>
</recommends>
<requires>
<!--
Mobile/tablet AND desktop supported
Ref: https://docs.flathub.org/docs/for-app-authors/metainfo-guidelines#display-size
-->
<display_length compare="ge">360</display_length>
</requires>
<translation type="gettext">com.mitchellh.ghostty</translation>

<!--
TODO: Generate manifest location data.
Ref: https://docs.flathub.org/docs/for-app-authors/metainfo-guidelines#manifest-location
<custom>
<value key="flathub::manifest">https://github.com/ghostty-org/ghostty/blob/<hash>/flatpak/com.mitchellh.ghostty.yml</value>
</custom>
-->
Comment on lines +43 to +51

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isnt enforced by the flathub review process. At least I havent ran into this at all when publishing flatpak manifests to Flathub

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It sounds like a requirement if you're publishing straight from here to Flathub, though. At least I see that Firefox and OBS are following it.


<releases>
<!-- TODO: Generate this automatically -->
<release version="1.0.1" date="2024-12-31">
<url type="details">https://ghostty.org/docs/install/release-notes/1-0-1</url>
</release>
</releases>
</component>
108 changes: 108 additions & 0 deletions flatpak/build-support/check-zig-cache.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#!/usr/bin/env bash
#
# This script checks if the flatpak/zig-packages.json file is up-to-date.
# If the `--update` flag is passed, it will update all necessary
# files to be up to date.
#
# The files owned by this are:
#
# - flatpak/zig-packages.json
#
# All of these are auto-generated and should not be edited manually.

# Nothing in this script should fail.
set -eu
set -o pipefail

WORK_DIR=$(mktemp -d)

if [[ ! "$WORK_DIR" || ! -d "$WORK_DIR" ]]; then
echo "could not create temp dir"
exit 1
fi

function cleanup {
rm -rf "$WORK_DIR"
}

trap cleanup EXIT

help() {
echo ""
echo "To fix, please (manually) re-run the script from the repository root,"
echo "commit, and submit a PR with the update:"
echo ""
echo " ./flatpak/build-support/check-zig-cache.sh --update"
echo " git add flatpak/zig-packages.json"
echo " git commit -m \"flatpak: update zig-packages.json\""
echo ""
}

# Turn Nix's base64 hashes into regular hexadecimal form
decode_hash() {
input=$1
input=${input#sha256-}
echo "$input" | base64 -d | od -vAn -t x1 | tr -d ' \n'
}

ROOT="$(realpath "$(dirname "$0")/../../")"
ZIG_PACKAGES_JSON="$ROOT/flatpak/zig-packages.json"
BUILD_ZIG_ZON_JSON="$ROOT/build.zig.zon.json"

if [ ! -f "${BUILD_ZIG_ZON_JSON}" ]; then
echo -e "\nERROR: build.zig.zon2json-lock missing."
help
exit 1
fi

if [ -f "${ZIG_PACKAGES_JSON}" ]; then
OLD_HASH=$(sha512sum "${ZIG_PACKAGES_JSON}" | awk '{print $1}')
fi

while read -r url sha256 dest; do
src_type=archive
sha256=$(decode_hash "$sha256")
git_commit=
if [[ "$url" =~ ^git\+* ]]; then
src_type=git
sha256=
url=${url#git+}
git_commit=${url##*#}
url=${url%%/\?ref*}
url=${url%%#*}
fi

jq \
-nec \
--arg type "$src_type" \
--arg url "$url" \
--arg git_commit "$git_commit" \
--arg dest "$dest" \
--arg sha256 "$sha256" \
'{
type: $type,
url: $url,
commit: $git_commit,
dest: $dest,
sha256: $sha256,
} | with_entries(select(.value != ""))'
done < <(jq -rc 'to_entries[] | [.value.url, .value.hash, "vendor/p/\(.key)"] | @tsv' "$BUILD_ZIG_ZON_JSON") |
jq -s '.' >"$WORK_DIR/zig-packages.json"

NEW_HASH=$(sha512sum "$WORK_DIR/zig-packages.json" | awk '{print $1}')

if [ "${OLD_HASH}" == "${NEW_HASH}" ]; then
echo -e "\nOK: flatpak/zig-packages.json unchanged."
exit 0
elif [ "${1:-}" != "--update" ]; then
echo -e "\nERROR: flatpak/zig-packages.json needs to be updated."
echo ""
echo " * Old hash: ${OLD_HASH}"
echo " * New hash: ${NEW_HASH}"
help
exit 1
else
mv "$WORK_DIR/zig-packages.json" "$ZIG_PACKAGES_JSON"
echo -e "\nOK: flatpak/zig-packages.json updated."
exit 0
fi
63 changes: 63 additions & 0 deletions flatpak/com.mitchellh.ghostty.Devel.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
app-id: com.mitchellh.ghostty.Devel
runtime: org.gnome.Platform
runtime-version: "47"
sdk: org.gnome.Sdk
sdk-extensions:
- org.freedesktop.Sdk.Extension.ziglang
default-branch: tip
command: ghostty
# Integrate the rename into zig build, maybe?
rename-desktop-file: com.mitchellh.ghostty.desktop
rename-appdata-file: com.mitchellh.ghostty.metainfo.xml
rename-icon: com.mitchellh.ghostty
desktop-file-name-suffix: " (Devel)"
finish-args:
# 3D rendering
- --device=dri
# Windowing
- --share=ipc
- --socket=fallback-x11
- --socket=wayland
# Allow user to specify additional config files in home by default
- --filesystem=home:ro
# So we can escape the sandbox
- --talk-name=org.freedesktop.Flatpak
cleanup:
- /include
- /lib/girepository-1.0
- /lib/pkgconfig
- /share/gir-1.0
- /share/pkgconfig
- /share/vala
- "*.la"
- "*.a"
- "*.so"

modules:
- dependencies.yml

- name: ghostty
buildsystem: simple
build-options:
append-path: /usr/lib/sdk/ziglang
build-commands:
- zig build
-Doptimize=Debug
-Dcpu=baseline
-Dflatpak=true
-Dstrip=false
-fno-sys=oniguruma
--prefix /app
--search-prefix /app
--system $PWD/vendor/p
sources:
- type: dir
path: ..
skip:
- flatpak/.flatpak-builder
- flatpak/builddir
- flatpak/repo
- zig-cache
- zig-out

- zig-packages.json
Loading