Maybe this helps someone like me who sometimes runs valgrind from nix-shell and wants to debug as well.
Problem: debugging via vgdb does not work
Start valgrind with vgdb in one terminal (“valgrind terminal”):
> nix-shell -p valgrind
$ valgrind --quiet --vgdb-error=0 --vgdb=full sleep 1
==2799760== (action at startup) vgdb me ...
==2799760==
==2799760== TO DEBUG THIS PROCESS USING GDB: start GDB like this
==2799760== /path/to/gdb sleep
==2799760== and then give GDB the following command
==2799760== target remote | /nix/store/z3k1ih7g5njqnbhns0anx8mw6zqjs1z3-valgrind-3.26.0/libexec/valgrind/../../bin/vgdb --pid=2799760
==2799760== --pid is optional if only one valgrind process is running
==2799760==
Start gdb in another terminal (“gdb terminal”) and follow valgrind’s hint:
$ gdb -q sleep
Reading symbols from sleep...
(gdb) target remote | /nix/store/z3k1ih7g5njqnbhns0anx8mw6zqjs1z3-valgrind-3.26.0/libexec/valgrind/../../bin/vgdb --pid=2799760
Remote debugging using | /nix/store/z3k1ih7g5njqnbhns0anx8mw6zqjs1z3-valgrind-3.26.0/libexec/valgrind/../../bin/vgdb --pid=2799760
❌️ Remote communication error. Target disconnected: error while reading: Connection reset by peer.
(gdb)