Hello,
I was wondering how I could start a database in the background with nix-shell for my program to interact with it
The idea is that I don’t have to always run it in the background but instead only when I’m developing on my project; and to really make my developer environment 100% pure.
What I have so far (all ideas) is that I start e.g. mongod in my shellHook but I cannot think of a way to stop it when I exit my shell.
Would my idea even work? Anything else that could pose problems?
What @ilkecan mentioned definitely works, and I’m using it in my dev shell.nix (extensively commented) that drops me in a shell with Erlang, Elixir, and Phoenix available, and a PostgreSQL instance is humming in the background. Exiting the shell will clean up everything using trap. You can also try it out with
IIRC, they exported an ‘up’ and ‘down’ command as part of the shell. These would in turn start and stop launchd user services. You could probably do something similar.
Thanks for the help guys! I’ve settled with this: lila/shell.nix at nix · legendofmiracles/lila · GitHub it starts both redis and mongod in the background (if it isn’t running already), and only kills it when no other shell is open.