got conditional direnv loading working for zsh and bash

This commit is contained in:
Gerg-L 2023-06-26 19:22:20 -04:00
parent f43d0b741c
commit f2974e6b13
5 changed files with 29 additions and 19 deletions

View file

@ -1,27 +1,34 @@
_: {pkgs, ...}: {
environment = {
systemPackages = builtins.attrValues {
inherit
(pkgs)
nix-direnv
direnv
;
};
systemPackages = [pkgs.direnv];
variables = {
DIRENV_LOG_FORMAT = "";
DIRENV_CONFIG = "${pkgs.nix-direnv}/share/nix-direnv";
DIRENV_CONFIG = "/etc/direnv";
};
etc."direnv/direnvrc".text = ''
source ${pkgs.nix-direnv}/share/nix-direnv/direnvrc
if [ -e $HOME/.config/direnv/direnvrc ] ; then
source $HOME/.config/direnv/direnvrc
fi
'';
};
programs = {
zsh.interactiveShellInit = ''
eval "$(direnv hook zsh)"
if [[ -o interactive ]] && ! printenv PATH | grep -qc '/nix/store' && [ -z "$IN_NIX_SHELL" ] ; then
eval "$(direnv hook zsh)"
fi
'';
bash.interactiveShellInit = ''
eval "$(direnv hook bash)"
'';
fish.interactiveShellInit = ''
direnv hook fish | source
if [ $- == *i* ] && ! printenv PATH | grep -qc '/nix/store' && [ -z "$IN_NIX_SHELL" ] ; then
eval "$(direnv hook bash)"
fi
'';
# fish.enable = true;
# fish.interactiveShellInit = ''
# if status --is-interactive; and not printenv PATH | grep -qc '/nix/store'; and [ -z "$IN_NIX_SHELL" ];
# direnv hook fish | source;
# echo "loaded direnv";
# end
# '';
};
}