programs/direnv: add enable*Integration options
Ability to disable shell hook is needed to use alternative shell hooks - e.g. direnv-instant. These options mirror NixOS's exactly.
This commit is contained in:
parent
7b1d394e7d
commit
6d323f4ffd
1 changed files with 20 additions and 3 deletions
|
|
@ -5,6 +5,13 @@
|
||||||
...
|
...
|
||||||
}: let
|
}: let
|
||||||
cfg = config.programs.direnv;
|
cfg = config.programs.direnv;
|
||||||
|
enabledOption =
|
||||||
|
x:
|
||||||
|
lib.mkEnableOption x
|
||||||
|
// {
|
||||||
|
default = true;
|
||||||
|
example = false;
|
||||||
|
};
|
||||||
format = pkgs.formats.toml {};
|
format = pkgs.formats.toml {};
|
||||||
in {
|
in {
|
||||||
meta.maintainers = [
|
meta.maintainers = [
|
||||||
|
|
@ -25,6 +32,16 @@ in {
|
||||||
description = "The wrapped direnv package.";
|
description = "The wrapped direnv package.";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enableBashIntegration = enabledOption ''
|
||||||
|
Bash integration
|
||||||
|
'';
|
||||||
|
enableZshIntegration = enabledOption ''
|
||||||
|
Zsh integration
|
||||||
|
'';
|
||||||
|
enableFishIntegration = enabledOption ''
|
||||||
|
Fish integration
|
||||||
|
'';
|
||||||
|
|
||||||
direnvrcExtra = lib.mkOption {
|
direnvrcExtra = lib.mkOption {
|
||||||
type = lib.types.lines;
|
type = lib.types.lines;
|
||||||
default = "";
|
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
|
if ${lib.boolToString cfg.loadInNixShell} || printenv PATH | grep -vqc '/nix/store'; then
|
||||||
eval "$(${lib.getExe cfg.finalPackage} hook zsh)"
|
eval "$(${lib.getExe cfg.finalPackage} hook zsh)"
|
||||||
fi
|
fi
|
||||||
|
|
@ -105,13 +122,13 @@ in {
|
||||||
|
|
||||||
#$NIX_GCROOT for "nix develop" https://github.com/NixOS/nix/blob/6db66ebfc55769edd0c6bc70fcbd76246d4d26e0/src/nix/develop.cc#L530
|
#$NIX_GCROOT for "nix develop" https://github.com/NixOS/nix/blob/6db66ebfc55769edd0c6bc70fcbd76246d4d26e0/src/nix/develop.cc#L530
|
||||||
#$IN_NIX_SHELL for "nix-shell"
|
#$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
|
if ${lib.boolToString cfg.loadInNixShell} || [ -z "$IN_NIX_SHELL$NIX_GCROOT$(printenv PATH | grep '/nix/store')" ] ; then
|
||||||
eval "$(${lib.getExe cfg.finalPackage} hook bash)"
|
eval "$(${lib.getExe cfg.finalPackage} hook bash)"
|
||||||
fi
|
fi
|
||||||
'';
|
'';
|
||||||
|
|
||||||
fish.interactiveShellInit = ''
|
fish.interactiveShellInit = lib.mkIf cfg.enableFishIntegration ''
|
||||||
if ${lib.boolToString cfg.loadInNixShell};
|
if ${lib.boolToString cfg.loadInNixShell};
|
||||||
or printenv PATH | grep -vqc '/nix/store';
|
or printenv PATH | grep -vqc '/nix/store';
|
||||||
${lib.getExe cfg.finalPackage} hook fish | source
|
${lib.getExe cfg.finalPackage} hook fish | source
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue