Skip to content

Commit ea38aee

Browse files
committed
Add flake.nix, build-flatpak
1 parent 6c0ecc7 commit ea38aee

File tree

3 files changed

+88
-0
lines changed

3 files changed

+88
-0
lines changed

flake.lock

Lines changed: 26 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
description = "A gemini browser";
3+
inputs = {
4+
nixpkgs.url = "github:NixOS/nixpkgs";
5+
};
6+
outputs = { self, nixpkgs }:
7+
with import nixpkgs { system = "x86_64-linux"; };
8+
{
9+
geopard = callPackage ./nix/geopard.nix {};
10+
build-flatpak = callPackage ./nix/build-flatpak.nix {};
11+
};
12+
}

nix/build-flatpak.nix

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{flatpak-builder, flatpak, stdenv, jq, dbus, docker, bash, writeShellApplication, writeTextFile}:
2+
let
3+
f = writeTextFile {
4+
name = "build-terminal.sh";
5+
text = ''
6+
meson dist --include-subprojects --no-tests;
7+
'';
8+
};
9+
in
10+
writeShellApplication {
11+
name = "build-flatpak";
12+
runtimeInputs = [flatpak-builder flatpak jq docker bash];
13+
text = ''
14+
# Read data from manifest
15+
folder=$1
16+
manifest=$2;
17+
name=$(< "$manifest" jq -r '.["modules"] | last | .["name"]');
18+
appid=$(< "$manifest" jq -r '.["app-id"]');
19+
runtime=$(< "$manifest" jq -r '"runtime/" + .["runtime"] + "/x86_64/" + .["runtime-version"]');
20+
21+
# Install flathub repo
22+
flatpak --verbose remote-add --system --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo;
23+
flatpak install --system -y "$runtime";
24+
25+
# Prepare build folder
26+
if [ -n "$(ls -A "$folder")" ]; then
27+
echo error: directory "$folder" is not empty;
28+
exit 1;
29+
fi
30+
rm -rf "$folder";
31+
mkdir "$folder";
32+
33+
# Generate dist archive and the release manifest
34+
flatpak-builder "$folder"/build "$manifest" --build-only --stop-at="$name" --keep-build-dirs --force-clean;
35+
< ${f} flatpak-builder "$folder"/build "$manifest" --build-shell="$name" --keep-build-dirs --state-dir="$folder"/state;
36+
< "$manifest" jq '(.["modules"] | last | .["sources"] | last) |= {type: "archive", path: "archive.tar.xz"}' > build-flatpak-auto/manifest-archive.json;
37+
38+
# Build the app from the dist archive, using the corrected manifest
39+
cd "$folder"/;
40+
mv state/build/"$name"/_flatpak_build/meson-dist/*.tar.xz archive.tar.xz;
41+
flatpak-builder build --repo repo manifest-archive.json --force-clean;
42+
flatpak build-bundle ./repo "$appid".flatpak "$appid"
43+
44+
# Put all the artifacts in a single folder
45+
mkdir artifacts;
46+
mv "$appid".flatpak artifacts/;
47+
mv manifest-archive.json artifacts/"$appid".json;
48+
mv archive.tar.xz artifacts/"$appid".tar.xz;
49+
'';
50+
}

0 commit comments

Comments
 (0)