From 5cf4c1037ae38e525b72f6ae208884d08907e2ca Mon Sep 17 00:00:00 2001 From: Alexander Heldt Date: Tue, 2 Jun 2026 10:07:08 +0200 Subject: [PATCH] pinwheel: Load direnv ZSH on devshell load --- hosts/pinwheel/modules/work/default.nix | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/hosts/pinwheel/modules/work/default.nix b/hosts/pinwheel/modules/work/default.nix index f2e9469..6411bff 100644 --- a/hosts/pinwheel/modules/work/default.nix +++ b/hosts/pinwheel/modules/work/default.nix @@ -22,6 +22,24 @@ in [[ "$PATH" == "${pkgs.bashInteractive}/bin:"* ]] || export PATH="${pkgs.bashInteractive}/bin:$PATH" } precmd_functions+=(_ensure_bash_interactive) + + # Source the zsh-specific rc file that nix-direnv emits ($DIRENV_ZSH_RC) + # so devshell completions and zsh setup are picked up. direnv itself only + # exports env vars, so without this hook the zsh side of the devshell is + # never loaded. Guarded by LAST_LOADED_DIRENV_ZSH_RC so we don't re-source + # it on every precmd. + _nix_direnv_bridge_hook() { + if [[ -n "$DIRENV_ZSH_RC" && "$LAST_LOADED_DIRENV_ZSH_RC" != "$DIRENV_ZSH_RC" ]]; then + if [[ -f "$DIRENV_ZSH_RC" ]]; then + source "$DIRENV_ZSH_RC" + export LAST_LOADED_DIRENV_ZSH_RC="$DIRENV_ZSH_RC" + echo "❄️ direnv zsh loaded..." + fi + fi + } + + autoload -Uz add-zsh-hook + add-zsh-hook precmd _nix_direnv_bridge_hook ''; # Configure IntelliJ to exclude .direnv from indexing