NixOS/nixpkgs — pull request #464 by the-kenny (2013-04-13 17:13:32+00:00)
Title: Add cleanupCmds option to pkgs.myEnvFun

This option allows the user to specify commands to run when the shell
exits. This can be used to cleanup operations done in `extraCmds'.

Please notice that the 'trap' approach required me to remove the `exec' in front of @shell@ in loadenv.sh. I don't think this is a problem, but it might be for special use cases.