How I managed to wire devshell, postgres, direnv and VSCode #194
Unanswered
yajo
asked this question in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
As I explained in #170 (comment), starting services when starting a
nix-shell
is kind of messy. Mostly for background services, such as Postgres. That was a conceptual failure for development IMHO.I tried with devshell-files and its s6-based services backend, but also didn't work out fine. It had a different purpose of what I wanted.
Well, here's how I did it.
This is how I build my shell (of course, pkgs has the usual devshell overlay, etc.):
The
writeScriptBin
part could have been replaced by devshell-files alias, but I felt like it was adding too much dependency for such a simple task. However, if you're using it, it's more ergonomic.An important part however is tini. It makes sure that, when exiting the IDE, all postgres subprocesses are properly reaped. Close the IDE, all is gone! Cool 😎
Now I add a task for the IDE (VSCode in my case):
Now I want Postgres to autostart when I start debugging a Python file, so I create this launch configuration:
Now all I have to do is to press F5 and:
nix-shell
gets all required dependencies.devshell/extra/services/postgres.nix
Lines 49 to 58 in d97df53
I'm quite happy with it! ❤️
Beta Was this translation helpful? Give feedback.
All reactions