I’m not totally understanding what you want to do, but maybe the inputDerivation of the shell is what you want.
https://github.com/NixOS/nixpkgs/pull/95536