@lilyball Besides the already proposed super interesting ideas (see also blog post), which I had no idea of, I’ve implemented a pure Nix function that gets all of the propagatedBuildInputs and buildInputs of a derivation here:
https://github.com/NixOS/nixpkgs/pull/85103/files#diff-44c2102a355f50131eb8f69fb7e7c18bR78
It’s also a sort of hack because you can reach infinite recursion with it, unless you pass it a list of known packages you don’t want it to iterate.
I noted my self to try the other methods once I’ll have more time to work on that PR.