How to get the latest unbroken commit for a broken package from Hydra

Hi all,

Two colleagues at Tweag helped me come up with this script that I found really useful. It helps you find the last successful build of a package from Hydra and spits out the nixpkgs commit like this:

 ./ haskellPackages.Frames
Hydra URL:
last working nixpkgs revision: "710fed5a2483f945b14f4a58af2cd3676b42d8c8", evaluated at Wed Mar 30 11:46:08 CEST 2022

I feel it could almost be included as nix run --latest-unbroken nixpkgs#haskellPackages.Frames.

Here is the script:

#!/usr/bin/env nix-shell
#! nix-shell --pure -i bash
#! nix-shell -p hydra-check -p curl -p jq
set -e

hydraURL=$(hydra-check --json "$package" | jq ".\"$package\" | .[0].build_url" -r)
echo "Hydra URL: $hydraURL"
evalID=$(curl -sH 'Accept: application/json' "$hydraURL" | jq '.jobsetevals | .[0]')
eval=$(curl -sH 'Accept: application/json'"$evalID")
rev=$(echo "$eval" | jq '.jobsetevalinputs.nixpkgs.revision')
evalDate=$(date --date @"$(echo "$eval" | jq '.timestamp')")
echo "last working nixpkgs revision: $rev, evaluated at $evalDate"

As alternative, could there be a cache of only unbroken packages? Something like nix run unbroken#haskellPackages.Frames? Not sure how to use this when a whole set of unbroken packages is required though.

Hydra does not have all commits, so you would need to git bisect to find the exact commit.

The only commit that would come to mind is right after marking all failed packages as broken in ZHF.

Also you probably mean branch since the cache is only contain unbroken commits.

You can also get the latest successful build via the “Links” tab of a job:

For example for age on Darwin:

Hosted by Flying Circus.