this post was submitted on 24 Jan 2025
13 points (100.0% liked)
Nix / NixOS
1932 readers
1 users here now
Main links
Videos
founded 2 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
In this case what I would recommend is to provide a command (perhaps inside that
nix develop
) that would set up all the images/services/data, and a second one to tear it down, and allow devs to run those commands themselves. This allows for more flexibility, e.g. multiplenix develop
shells of the same project, but only one does the stateful stuff, coming back to the same shell later in the day without waiting for the setup. Most importantly it would allow for easy clean-up if the shell is shutdown unexpectedly and doesn't have time to clean up itself, e.g. SIGKILL or power loss. It can be as simple as usingwriteShellScriptBin
to string together commands (instead of doing it in the shellHook as you presumably are doing right now), or as complex and flexible as https://github.com/svanderburg/nix-processmgmt .Then, if you really want to automate it, you can simply add
your-setup-command
andtrap "your-cleanup-command" EXIT
to yourshellHook
.I would externalize it into a separate script/command anyway (the skeleton already exists).
However, knowing myself, I would certainly forget cleaning up manually once in a while. My goal was to create truly self-contained, stupid-simple dev environments - or get as close as possible to it.