From a18332828abca22f10c8e0f817941bfc4c808993 Mon Sep 17 00:00:00 2001 From: "Jeffrey C. Ollie" Date: Sat, 23 Aug 2025 21:25:19 -0500 Subject: [PATCH] nix: update zon2nix - Builds with Zig 0.15 now (but still works just fine with Zig 0.14 projects). - Fixes a double-free if nix-prefetch-git can't be found or errors out - Adds support for generating Flatpak package metadata natively. --- .github/workflows/test.yml | 30 +----- .github/workflows/update-colorschemes.yml | 2 - build.zig.zon.nix | 1 + flake.lock | 25 +++-- flake.nix | 7 +- flatpak/build-support/check-zig-cache.sh | 108 ---------------------- nix/build-support/check-zig-cache.sh | 39 +++++--- 7 files changed, 53 insertions(+), 159 deletions(-) delete mode 100755 flatpak/build-support/check-zig-cache.sh diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8910d8c07..a5a2d1ef0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -20,7 +20,6 @@ jobs: - build-macos - build-macos-matrix - build-windows - - flatpak-check-zig-cache - test - test-gtk - test-gtk-ng @@ -954,33 +953,6 @@ jobs: build-args: | DISTRO_VERSION=13 - 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@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 - - name: Setup Cache - uses: namespacelabs/nscloud-cache-action@305bfa7ea980a858d511af4899414a84847c7991 # v1.2.16 - with: - path: | - /nix - /zig - - name: Setup Nix - uses: cachix/install-nix-action@fc6e360bedc9ee72d75e701397f0bb30dce77568 # v31.5.2 - with: - nix_path: nixpkgs=channel:nixos-unstable - - uses: cachix/cachix-action@0fc020193b5a1fa3ac4575aa3a7d3aa6a35435ad # v16 - 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" @@ -996,7 +968,7 @@ jobs: - arch: aarch64 runner: namespace-profile-ghostty-md-arm64 runs-on: ${{ matrix.variant.runner }} - needs: [flatpak-check-zig-cache, test] + needs: test steps: - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 - uses: flatpak/flatpak-github-actions/flatpak-builder@10a3c29f0162516f0f68006be14c92f34bd4fa6c # v6.5 diff --git a/.github/workflows/update-colorschemes.yml b/.github/workflows/update-colorschemes.yml index e1ee92168..3848a7ad4 100644 --- a/.github/workflows/update-colorschemes.yml +++ b/.github/workflows/update-colorschemes.yml @@ -50,8 +50,6 @@ jobs: if ! git diff --exit-code build.zig.zon; then nix develop -c ./nix/build-support/check-zig-cache.sh --update nix develop -c ./nix/build-support/check-zig-cache.sh - nix develop -c ./flatpak/build-support/check-zig-cache.sh --update - nix develop -c ./flatpak/build-support/check-zig-cache.sh fi # Verify the build still works. We choose an arbitrary build type diff --git a/build.zig.zon.nix b/build.zig.zon.nix index 6450b8df9..d3b41b58a 100644 --- a/build.zig.zon.nix +++ b/build.zig.zon.nix @@ -49,6 +49,7 @@ inherit name rev hash; url = url_without_query; deepClone = false; + fetchSubmodules = false; }; fetchZigArtifact = { diff --git a/flake.lock b/flake.lock index 0374b3e5a..ba1adb08a 100644 --- a/flake.lock +++ b/flake.lock @@ -47,6 +47,19 @@ "url": "https://channels.nixos.org/nixos-25.05/nixexprs.tar.xz" } }, + "nixpkgs_2": { + "locked": { + "lastModified": 1755972213, + "narHash": "sha256-VYK7aDAv8H1enXn1ECRHmGbeY6RqLnNwUJkOwloIsko=", + "rev": "73e96df7cff5783f45e21342a75a1540c4eddce4", + "type": "tarball", + "url": "https://releases.nixos.org/nixos/unstable-small/nixos-25.11pre850642.73e96df7cff5/nixexprs.tar.xz" + }, + "original": { + "type": "tarball", + "url": "https://channels.nixos.org/nixos-unstable-small/nixexprs.tar.xz" + } + }, "root": { "inputs": { "flake-compat": "flake-compat", @@ -102,22 +115,20 @@ "flake-utils": [ "flake-utils" ], - "nixpkgs": [ - "nixpkgs" - ] + "nixpkgs": "nixpkgs_2" }, "locked": { - "lastModified": 1742104771, - "narHash": "sha256-LhidlyEA9MP8jGe1rEnyjGFCzLLgCdDpYeWggibayr0=", + "lastModified": 1756000480, + "narHash": "sha256-fR5pdcjO0II5MNdCzqvyokyuFkmff7/FyBAjUS6sMfA=", "owner": "jcollie", "repo": "zon2nix", - "rev": "56c159be489cc6c0e73c3930bd908ddc6fe89613", + "rev": "d9dc9ef1ab9ae45b5c9d80c6a747cc9968ee0c60", "type": "github" }, "original": { "owner": "jcollie", "repo": "zon2nix", - "rev": "56c159be489cc6c0e73c3930bd908ddc6fe89613", + "rev": "d9dc9ef1ab9ae45b5c9d80c6a747cc9968ee0c60", "type": "github" } } diff --git a/flake.nix b/flake.nix index 7cf58b27c..99f7fcb7c 100644 --- a/flake.nix +++ b/flake.nix @@ -24,9 +24,12 @@ }; zon2nix = { - url = "github:jcollie/zon2nix?rev=56c159be489cc6c0e73c3930bd908ddc6fe89613"; + url = "github:jcollie/zon2nix?rev=d9dc9ef1ab9ae45b5c9d80c6a747cc9968ee0c60"; inputs = { - nixpkgs.follows = "nixpkgs"; + # Don't override nixpkgs until Zig 0.15 is available in the Nix branch + # we are using for "normal" builds. + # + # nixpkgs.follows = "nixpkgs"; flake-utils.follows = "flake-utils"; }; }; diff --git a/flatpak/build-support/check-zig-cache.sh b/flatpak/build-support/check-zig-cache.sh deleted file mode 100755 index bea718640..000000000 --- a/flatpak/build-support/check-zig-cache.sh +++ /dev/null @@ -1,108 +0,0 @@ -#!/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 diff --git a/nix/build-support/check-zig-cache.sh b/nix/build-support/check-zig-cache.sh index 49997ac1a..33e57e790 100755 --- a/nix/build-support/check-zig-cache.sh +++ b/nix/build-support/check-zig-cache.sh @@ -9,6 +9,7 @@ # - build.zig.zon.nix # - build.zig.zon.txt # - build.zig.zon.json +# - flatpak/zig-packages.json # # All of these are auto-generated and should not be edited manually. @@ -34,8 +35,8 @@ help() { echo "commit, and submit a PR with the update:" echo "" echo " ./nix/build-support/check-zig-cache-hash.sh --update" - echo " git add build.zig.zon.nix build.zig.zon.txt build.zig.zon.json" - echo " git commit -m \"nix: update build.zig.zon.nix build.zig.zon.txt build.zig.zon.json\"" + echo " git add build.zig.zon.nix build.zig.zon.txt build.zig.zon.json flatpak/zig-packages.json" + echo " git commit -m \"nix: update build.zig.zon.nix build.zig.zon.txt build.zig.zon.json flatpak/zig-packages.json\"" echo "" } @@ -44,6 +45,7 @@ BUILD_ZIG_ZON="$ROOT/build.zig.zon" BUILD_ZIG_ZON_NIX="$ROOT/build.zig.zon.nix" BUILD_ZIG_ZON_TXT="$ROOT/build.zig.zon.txt" BUILD_ZIG_ZON_JSON="$ROOT/build.zig.zon.json" +ZIG_PACKAGES_JSON="$ROOT/flatpak/zig-packages.json" if [ -f "${BUILD_ZIG_ZON_NIX}" ]; then OLD_HASH_NIX=$(sha512sum "${BUILD_ZIG_ZON_NIX}" | awk '{print $1}') @@ -69,27 +71,40 @@ elif [ "$1" != "--update" ]; then exit 1 fi -zon2nix "$BUILD_ZIG_ZON" --nix "$WORK_DIR/build.zig.zon.nix" --txt "$WORK_DIR/build.zig.zon.txt" --json "$WORK_DIR/build.zig.zon.json" +if [ -f "${ZIG_PACKAGES_JSON}" ]; then + OLD_HASH_FLATPAK=$(sha512sum "${ZIG_PACKAGES_JSON}" | awk '{print $1}') +elif [ "$1" != "--update" ]; then + echo -e "\nERROR: flatpak/zig-packages.json missing." + help + exit 1 +fi + +zon2nix "$BUILD_ZIG_ZON" --nix "$WORK_DIR/build.zig.zon.nix" --txt "$WORK_DIR/build.zig.zon.txt" --json "$WORK_DIR/build.zig.zon.json" --flatpak "$WORK_DIR/zig-packages.json" alejandra --quiet "$WORK_DIR/build.zig.zon.nix" -prettier --write "$WORK_DIR/build.zig.zon.json" +prettier --log-level warn --write "$WORK_DIR/build.zig.zon.json" +prettier --log-level warn --write "$WORK_DIR/zig-packages.json" NEW_HASH_NIX=$(sha512sum "$WORK_DIR/build.zig.zon.nix" | awk '{print $1}') NEW_HASH_TXT=$(sha512sum "$WORK_DIR/build.zig.zon.txt" | awk '{print $1}') NEW_HASH_JSON=$(sha512sum "$WORK_DIR/build.zig.zon.json" | awk '{print $1}') +NEW_HASH_FLATPAK=$(sha512sum "$WORK_DIR/zig-packages.json" | awk '{print $1}') -if [ "${OLD_HASH_NIX}" == "${NEW_HASH_NIX}" ] && [ "${OLD_HASH_TXT}" == "${NEW_HASH_TXT}" ] && [ "${OLD_HASH_JSON}" == "${NEW_HASH_JSON}" ]; then +if [ "${OLD_HASH_NIX}" == "${NEW_HASH_NIX}" ] && [ "${OLD_HASH_TXT}" == "${NEW_HASH_TXT}" ] && [ "${OLD_HASH_JSON}" == "${NEW_HASH_JSON}" ] && [ "${OLD_HASH_FLATPAK}" == "${NEW_HASH_FLATPAK}" ]; then echo -e "\nOK: build.zig.zon.nix unchanged." echo -e "OK: build.zig.zon.txt unchanged." echo -e "OK: build.zig.zon.json unchanged." + echo -e "OK: flatpak/zig-packages.json unchanged." exit 0 elif [ "$1" != "--update" ]; then echo -e "\nERROR: build.zig.zon.nix, build.zig.zon.txt, or build.zig.zon.json needs to be updated.\n" - echo " * Old build.zig.zon.nix hash: ${OLD_HASH_NIX}" - echo " * New build.zig.zon.nix hash: ${NEW_HASH_NIX}" - echo " * Old build.zig.zon.txt hash: ${OLD_HASH_TXT}" - echo " * New build.zig.zon.txt hash: ${NEW_HASH_TXT}" - echo " * Old build.zig.zon.json hash: ${OLD_HASH_JSON}" - echo " * New build.zig.zon.json hash: ${NEW_HASH_JSON}" + echo " * Old build.zig.zon.nix hash: ${OLD_HASH_NIX}" + echo " * New build.zig.zon.nix hash: ${NEW_HASH_NIX}" + echo " * Old build.zig.zon.txt hash: ${OLD_HASH_TXT}" + echo " * New build.zig.zon.txt hash: ${NEW_HASH_TXT}" + echo " * Old build.zig.zon.json hash: ${OLD_HASH_JSON}" + echo " * New build.zig.zon.json hash: ${NEW_HASH_JSON}" + echo " * Old flatpak/zig-packages.json hash: ${OLD_HASH_FLATPAK}" + echo " * New flatpak/zig-packages.json hash: ${NEW_HASH_FLATPAK}" help exit 1 else @@ -99,6 +114,8 @@ else echo -e "OK: build.zig.zon.txt updated." mv "$WORK_DIR/build.zig.zon.json" "$BUILD_ZIG_ZON_JSON" echo -e "OK: build.zig.zon.json updated." + mv "$WORK_DIR/zig-packages.json" "$ZIG_PACKAGES_JSON" + echo -e "OK: flatpak/zig-packages.json updated." exit 0 fi