I might give this idea another go myself with this nice rust library. With some heuristics one could partition the recursive closure of dependencies in a way optimizes for reuse (e.g. try to compute shared subtrees). Probably more efficient than a random tar of e.g. the entire root file system of a buildroot android system.