I setup a next.js project with pkgs.mkshell, and used nix develop to automatically build the project. However, when I leave the shell, the files persist. How should/can(?) I setup my shell.nix so that files in the directory it drops down into are automatically removed when leaving the ephemeral shell?
You could achieve something like that using bubblewrap; effectively a container. You can tell it to mount tmpfs wherever you like. That has other issues though.
That’s a big of a complex setup which other people potentially working with you may not want to have. A clean task is just better. If you’re using git anyways, you can also just use
git clean
.