From 10b2ccf60ada7dd66af983d21cc2ec746df57e11 Mon Sep 17 00:00:00 2001 From: Johannes Kresner Date: Mon, 2 Nov 2026 16:32:11 +0100 Subject: [PATCH] nix: use release binaries as default package The release job records the tarball hashes in bin.json and commits it ([skip ci]); flake.nix fetches the binary from the release on x86_64-linux and aarch64-darwin and builds from source elsewhere. Drop x86_64-darwin, nixpkgs no longer evaluates it. Co-Authored-By: Claude Opus 5.5 --- .gitea/workflows/build.yml | 18 ++++++++++ .gitea/workflows/ci.yml | 21 ----------- bin.json | 7 ++++ flake.nix | 71 ++++++++++++++++++++++++++------------ 4 files changed, 74 insertions(+), 43 deletions(-) delete mode 100644 .gitea/workflows/ci.yml create mode 100644 bin.json diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml index dedba56..aaa56d0 100644 --- a/.gitea/workflows/build.yml +++ b/.gitea/workflows/build.yml @@ -2,6 +2,7 @@ name: build on: push: branches: [main] + paths-ignore: [bin.json] env: MACOS_SDK: "14.5" jobs: @@ -64,6 +65,10 @@ jobs: needs: [build, version] runs-on: ubuntu-latest steps: + # main, not the build sha: bin.json is committed on top of it + - uses: actions/checkout@v4 + with: + ref: main - uses: actions/download-artifact@v3 with: path: dist @@ -88,3 +93,16 @@ jobs: curl -fsS -X POST -H "Authorization: token $TOKEN" \ -F "attachment=@$f" "$API/releases/$id/assets?name=$(basename "$f")" done + # flake.nix reads bin.json to fetch these tarballs instead of building from source + - env: + VERSION: ${{ needs.version.outputs.version }} + run: | + jq -Rn --arg v "$VERSION" \ + '{version: $v, sha256: ([inputs | split(" ") | {(.[1] | ltrimstr("hx-") | rtrimstr(".tar.gz")): .[0]}] | add)}' \ + < dist/SHA256SUMS > bin.json + git config user.name gitea-actions + git config user.email gitea-actions@git.jokresner.de + git add bin.json + git commit -m "ci: bin.json v$VERSION" + git pull --rebase origin main + git push origin HEAD:main diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml deleted file mode 100644 index 22f3451..0000000 --- a/.gitea/workflows/ci.yml +++ /dev/null @@ -1,21 +0,0 @@ -name: ci -on: [push, pull_request] -jobs: - check: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: dtolnay/rust-toolchain@stable - with: - components: rustfmt, clippy, rust-analyzer - - run: cargo fmt --all --check - - run: cargo clippy --workspace --all-targets -- -D warnings - - run: cargo test --workspace - - run: cargo build && sh tests/e2e.sh - - run: python3 tests/tui_smoke.py - - run: sh tests/lens_e2e.sh - - run: pip install ruff && sh tests/m4_e2e.sh - - run: sh tests/m5_e2e.sh - - run: sh tests/m6_e2e.sh - - run: python3 tests/tui_lspinstall.py - - run: sh tests/m7_e2e.sh diff --git a/bin.json b/bin.json new file mode 100644 index 0000000..f9bebeb --- /dev/null +++ b/bin.json @@ -0,0 +1,7 @@ +{ + "version": "0.1.0", + "sha256": { + "aarch64-apple-darwin": "b6c5b91a839ceb80be69d24a94fb8114f4150a039b7f8873381aa1efcb35a26c", + "x86_64-unknown-linux-musl": "a5079b8655af0046b4cca0af76e118b3d91c3048f6c3eab4f763a1bd4f85ba62" + } +} diff --git a/flake.nix b/flake.nix index a093d2c..ea1db12 100644 --- a/flake.nix +++ b/flake.nix @@ -6,37 +6,64 @@ outputs = { self, nixpkgs }: let - systems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ]; + systems = [ "x86_64-linux" "aarch64-linux" "aarch64-darwin" ]; forAll = f: nixpkgs.lib.genAttrs systems (s: f nixpkgs.legacyPackages.${s}); + # release binaries, bin.json is rewritten by the release job in .gitea/workflows/build.yml + bin = builtins.fromJSON (builtins.readFile ./bin.json); + targets = { + x86_64-linux = "x86_64-unknown-linux-musl"; + aarch64-darwin = "aarch64-apple-darwin"; + }; in { - packages = forAll (pkgs: rec { - hx = pkgs.rustPlatform.buildRustPackage { - pname = "hx"; - version = (builtins.fromTOML (builtins.readFile ./Cargo.toml)).workspace.package.version; - src = pkgs.lib.cleanSource ./.; - cargoLock.lockFile = ./Cargo.lock; - cargoBuildFlags = [ "-p" "hx-cli" ]; - # ponytail: tests skipped (need git/network); enable when hermetic. - doCheck = false; - # rustls may build aws-lc-sys (cmake) depending on feature set. - nativeBuildInputs = [ pkgs.cmake pkgs.perl ]; - dontUseCmakeConfigure = true; - meta = { - description = "Minimal Rust coding agent using existing subscriptions"; - license = pkgs.lib.licenses.unlicense; - mainProgram = "hx"; + packages = forAll ( + pkgs: + let + target = targets.${pkgs.stdenv.hostPlatform.system} or ""; + hasBin = bin.sha256 ? ${target}; + + hx = pkgs.rustPlatform.buildRustPackage { + pname = "hx"; + version = (builtins.fromTOML (builtins.readFile ./Cargo.toml)).workspace.package.version; + src = pkgs.lib.cleanSource ./.; + cargoLock.lockFile = ./Cargo.lock; + cargoBuildFlags = [ "-p" "hx-cli" ]; + # ponytail: tests skipped (need git/network); enable when hermetic. + doCheck = false; + # rustls may build aws-lc-sys (cmake) depending on feature set. + nativeBuildInputs = [ pkgs.cmake pkgs.perl ]; + dontUseCmakeConfigure = true; + meta = { + description = "Minimal Rust coding agent using existing subscriptions"; + license = pkgs.lib.licenses.unlicense; + mainProgram = "hx"; + }; }; - }; - default = hx; - }); + + hx-bin = pkgs.runCommand "hx-${bin.version}" { meta.mainProgram = "hx"; } '' + mkdir -p $out/bin + tar -xzf ${ + pkgs.fetchurl { + url = "https://git.jokresner.de/johannes/hx/releases/download/v${bin.version}/hx-${target}.tar.gz"; + sha256 = bin.sha256.${target}; + } + } -C $out/bin hx + ''; + in + { + inherit hx; + # prebuilt binary where the release has one, source build elsewhere + default = if hasBin then hx-bin else hx; + } + // pkgs.lib.optionalAttrs hasBin { inherit hx-bin; } + ); apps = forAll (pkgs: rec { - hx = { type = "app"; program = "${self.packages.${pkgs.system}.hx}/bin/hx"; }; + hx = { type = "app"; program = "${self.packages.${pkgs.system}.default}/bin/hx"; }; default = hx; }); - overlays.default = _: prev: { hx = self.packages.${prev.system}.hx; }; + overlays.default = _: prev: { hx = self.packages.${prev.system}.default; }; devShells = forAll (pkgs: { default = pkgs.mkShell {