Interactively developing nixpkgs derivations with nix-shell / nix develop

When hacking a nixpkgs derivation, it can be useful be dropped into an environment that resembles the one in which the derivation will be built, run some of the phases manually and generally poke around interactively.

I’m pretty sure that in the past I managed to do this sort of thing with nix-shell and/or nix develop, but today I’ve tripped up countless times in the attempt and am getting demoralized by all the bruises I’ve picked up in the process.

Can you point to some guide for interactive hacking on nixpkgs derivations, or give some hints?

FWIW, some highlights of my problems:

  • nix-shell --pure -I nixpkgs=~/src/nixpkgs -A the-package-I-want-to-hack seems like a good start, but when I try to run some of the phases to get into reach the state in which I want to poke around, I never manage to find an invocation that succeeds.
  • nix develop … well, I haven’t found an invocation that drops me into a shell with the phases defined.