programs/direnv: add enable[shell]Integration options (#1680)
Some checks failed
Test / test-stable (push) Has been cancelled
Test / install-against-stable (push) Has been cancelled
Test / install-flake (push) Has been cancelled
Update website / Build (push) Has been cancelled
Update website / Deploy (push) Has been cancelled

This commit is contained in:
Michael Hoang 2026-01-16 11:11:07 +00:00 committed by GitHub
commit 8b720b9662
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -5,6 +5,13 @@
...
}: let
cfg = config.programs.direnv;
enabledOption =
x:
lib.mkEnableOption x
// {
default = true;
example = false;
};
format = pkgs.formats.toml {};
in {
meta.maintainers = [
@ -25,6 +32,16 @@ in {
description = "The wrapped direnv package.";
};
enableBashIntegration = enabledOption ''
Bash integration
'';
enableZshIntegration = enabledOption ''
Zsh integration
'';
enableFishIntegration = enabledOption ''
Fish integration
'';
direnvrcExtra = lib.mkOption {
type = lib.types.lines;
default = "";
@ -97,7 +114,7 @@ in {
};
};
};
zsh.interactiveShellInit = ''
zsh.interactiveShellInit = lib.mkIf cfg.enableZshIntegration ''
if ${lib.boolToString cfg.loadInNixShell} || printenv PATH | grep -vqc '/nix/store'; then
eval "$(${lib.getExe cfg.finalPackage} hook zsh)"
fi
@ -105,13 +122,13 @@ in {
#$NIX_GCROOT for "nix develop" https://github.com/NixOS/nix/blob/6db66ebfc55769edd0c6bc70fcbd76246d4d26e0/src/nix/develop.cc#L530
#$IN_NIX_SHELL for "nix-shell"
bash.interactiveShellInit = ''
bash.interactiveShellInit = lib.mkIf cfg.enableBashIntegration ''
if ${lib.boolToString cfg.loadInNixShell} || [ -z "$IN_NIX_SHELL$NIX_GCROOT$(printenv PATH | grep '/nix/store')" ] ; then
eval "$(${lib.getExe cfg.finalPackage} hook bash)"
fi
'';
fish.interactiveShellInit = ''
fish.interactiveShellInit = lib.mkIf cfg.enableFishIntegration ''
if ${lib.boolToString cfg.loadInNixShell};
or printenv PATH | grep -vqc '/nix/store';
${lib.getExe cfg.finalPackage} hook fish | source