devbox
devbox copied to clipboard
[Feature]: exit_hook like in devbox.json
Is your feature request related to a problem you're trying to solve? Please describe. I often encounter a challenge when working with environment variables, particularly in managing domain configurations during development sessions. For instance, I frequently need to add and remove domain entries manually when starting or ending my development environment. This manual process is time-consuming and prone to errors. For example, I'm always frustrated when I forget to remove a domain entry after a session, leading to potential conflicts or security issues.
Describe the solution you'd like I would like to introduce an exit_hook feature, similar to the existing init_hook, that automatically executes specified scripts or command lines upon exiting the environment. This feature would allow users to define cleanup or reset tasks that need to be performed when they are done with their development session.
For instance, after using init_hook to add domain entries (e.g., sudo hostctl add domains expensify dev.new.expensify.com), the exit_hook would automatically remove these entries (e.g., sudo hostctl remove expensify) when the session ends. This automation would ensure a clean and secure development environment without manual intervention.
Describe alternatives you've considered
- Create a feature like in devbox.json : https://docs.docker.com/compose/compose-file/compose-file-v3/#extra_hosts
- Create a plugin for dnsmasq : where you can configure the dnsmasq.conf to create a containerized DNS host without touching the /etc/hosts of the host system
Additional context This feature would enhance workflow efficiency and security for developers who frequently modify their environment for testing or development purposes. I am not aware of any previous requests for this feature. If this has been discussed or requested before, I would appreciate a link to that discussion for further insights.
Example usage:
init_hook: ["sudo hostctl add domains expensify dev.new.expensify.com"] exit_hook: ["sudo hostctl remove expensify"]
### Tasks
+1 to @ebauger's suggestion. Right now running into an issue where after activating a virtual environment with poetry, I now have to exit twice. Don't appear to have the problem with vanilla . .venv/bin/activate though (i.e., only type exit once to get out of devbox and venv at the same time).
Can probably write a tiny shell script with trap to do all the above, but that kinda defeats some of the utility of devbox over asdf + poetry / docker as I use them now.
For now can work around the problem by using stdlib venv, poetry install then just source the former without any of the extra features of poetry.
I would also find this very useful. In our case we would like to automatically stop our services when exiting a development shell.
+1 this will be super useful so it will automatically executes something like atuin sync so you can have your command line history saved as by default it will be erased when you exit a devbox shell.