How to setup development workflow for python development with Emacs

I am trying to setup a development environment with Emacs.
What I am looking for is something like that:

  • (Emacs is already running, and is not launched within a nix-shell)
  • from within Emacs, I open a (python) project
  • Emacs picks up the right dependencies (including python and everything) from the shell.nix file, sets up the environment and enters it
  • I code, then for instance launch a python REPL, send the code, and it Just Works®

This is pretty much what I already do with Rust (except that I don’t run the program, I just compile it), but it’s a bit of a cheat because I have installed user-wide cargo and the rust compiler, and cargo takes care of everything (especially dependencies).

However, there are two things I fail to do:

  1. make Emacs get within a nix environment. Although there are Emacs packages that claim (maybe?) to do that (for instance, nix-buffer, nix-sandbox, …), none seems to be working. At least, I can’t get any to wok.
  2. make the shell available offline, ie. if I gc, I still want to be able to enter my development environment.

I’m asking this with the Python setup, but I would like to understand how to do it with any kind of nix environment.