Wouldn’t it be enough to checkout the commit where a-x.0 was updated, rather than the last known commit where a is at x.0? That way, if the packagr built successfully at that commit, you know it’s a good version.
We do something similar (and the way more manual) here[0].
[0]: https://github.com/dapphub/dapptools/blob/master/overlay.nix...