Add cleanupCmds option to pkgs.myEnvFun. The downside is that /bin/sh remains in memory to be able to execute cleanup commands.