For example, if PostgreSQL is started for a dev environment, it will keep running when exiting the shell, or when arbitrary files are created in shellHook
that are not needed afterwards.
Somewhat perplexed that I was only able to find Killing background processes started in nix-shell, after 15 minutes of searching. Maybe I was looking at the wrong places.
Are there better/more canonical ways to do this?
Thank you!
UPDATE: See an annotated version with inline bash commands to trap
here.
shellHook =
let
# NOTE These are equivalent.
#
# shellHook = shellHook =
# '' ''
# trap \ trap \
# " "
# '' echo lofa
# + '' sleep 2
# echo lofa echo miez
# sleep 2 " \
# echo miez EXIT
# '' ''
# + '' ;
# " \
# EXIT
# ''
# ;
# Helper function to achieve the same
cleanUp =
shell_commands:
''
trap \
"
${ builtins.concatStringsSep "" shell_commands }
" \
EXIT
''
;
in
cleanUp [
''
echo -n "POSTGRES CLEANUP START..."
''
( builtins.readFile ./postgres/clean-up.sh )
''
echo "END"
''
]
;