fix: guard shellHook heavy ops behind DIRENV_DIR check

When direnv evaluates the shellHook (DIRENV_DIR is set), skip mix local,
service startup, pre-commit install, and the welcome banner. These
operations block direnv and trigger nix profile cleanup hangs on macOS.
Only run them in interactive nix develop sessions.
This commit is contained in:
Graham McInitre 2026-07-16 08:54:55 -05:00
parent 3914d2e0b6
commit e58767cf00

View file

@ -282,45 +282,53 @@ mkShell {
# Ensure Erlang can find NIF libraries
export ERL_AFLAGS="-kernel shell_history enabled"
# Install Hex and Rebar3 if not already installed
mix local.hex --force --if-missing > /dev/null 2>&1
mix local.rebar --force --if-missing > /dev/null 2>&1
# Skip heavy setup when running inside direnv (DIRENV_DIR is set).
# direnv evaluates the shellHook to load env vars only; running mix,
# starting services, or installing pre-commit hooks would block the
# prompt and cause nix profile cleanup hangs on macOS.
if [ -z "$DIRENV_DIR" ]; then
# Running in nix develop (interactive shell)
# Auto-start services on first shell entry
if [ ! -f "${servicesFlag}" ]; then
${startServices}/bin/start-services
# Install Hex and Rebar3 if not already installed
mix local.hex --force --if-missing > /dev/null 2>&1
mix local.rebar --force --if-missing > /dev/null 2>&1
# Run migrations if databases exist and Mix deps are available
if [ -d "deps" ] && mix ecto.migrate 2>/dev/null; then
echo " Database migrations applied"
# Auto-start services on first shell entry
if [ ! -f "${servicesFlag}" ]; then
${startServices}/bin/start-services
# Run migrations if databases exist and Mix deps are available
if [ -d "deps" ] && mix ecto.migrate 2>/dev/null; then
echo " Database migrations applied"
fi
fi
# Install pre-commit hooks
${pre-commit-check.shellHook}
# Welcome message
echo ""
echo -e "''${BLUE}''${NC}"
echo -e "''${BLUE} ''${NC}"
echo -e "''${BLUE}''${NC} ''${GREEN}Towerops Development Environment''${NC} ''${BLUE}''${NC}"
echo -e "''${BLUE} ''${NC}"
echo -e "''${BLUE}''${NC}"
echo ""
echo -e "''${GREEN}Available commands:''${NC}"
echo " mix phx.server - Start Phoenix development server"
echo " mix test - Run test suite"
echo " mix precommit - Run pre-commit checks (format, credo, test)"
echo " start-services - Start PostgreSQL and Redis"
echo " stop-services - Stop PostgreSQL and Redis"
echo " mix ecto.reset - Reset database (drop, create, migrate, seed)"
echo ""
echo -e "''${GREEN}Services:''${NC}"
echo " PostgreSQL: ${pgHost}:${pgPort}"
echo " Redis: ${pgHost}:${redisPort}"
echo ""
echo -e "''${GREEN}Documentation:''${NC}"
echo " See CLAUDE.md and docs/nix.md for more information"
echo ""
fi
# Install pre-commit hooks
${pre-commit-check.shellHook}
# Welcome message
echo ""
echo -e "''${BLUE}''${NC}"
echo -e "''${BLUE} ''${NC}"
echo -e "''${BLUE}''${NC} ''${GREEN}Towerops Development Environment''${NC} ''${BLUE}''${NC}"
echo -e "''${BLUE} ''${NC}"
echo -e "''${BLUE}''${NC}"
echo ""
echo -e "''${GREEN}Available commands:''${NC}"
echo " mix phx.server - Start Phoenix development server"
echo " mix test - Run test suite"
echo " mix precommit - Run pre-commit checks (format, credo, test)"
echo " start-services - Start PostgreSQL and Redis"
echo " stop-services - Stop PostgreSQL and Redis"
echo " mix ecto.reset - Reset database (drop, create, migrate, seed)"
echo ""
echo -e "''${GREEN}Services:''${NC}"
echo " PostgreSQL: ${pgHost}:${pgPort}"
echo " Redis: ${pgHost}:${redisPort}"
echo ""
echo -e "''${GREEN}Documentation:''${NC}"
echo " See CLAUDE.md and docs/nix.md for more information"
echo ""
'';
}