mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-18 03:30:45 +00:00
nixos/direnv: add enable{Bash,Fish,Zsh}Integrations
use shorthand function for enabled by default options
This commit is contained in:
parent
008173588b
commit
ee3da00d59
|
@ -6,6 +6,13 @@
|
|||
}:
|
||||
let
|
||||
cfg = config.programs.direnv;
|
||||
enabledOption =
|
||||
x:
|
||||
lib.mkEnableOption x
|
||||
// {
|
||||
default = true;
|
||||
example = false;
|
||||
};
|
||||
in
|
||||
{
|
||||
options.programs.direnv = {
|
||||
|
@ -18,6 +25,16 @@ in
|
|||
|
||||
package = lib.mkPackageOption pkgs "direnv" { };
|
||||
|
||||
enableBashIntegration = enabledOption ''
|
||||
Bash integration
|
||||
'';
|
||||
enableZshIntegration = enabledOption ''
|
||||
Zsh integration
|
||||
'';
|
||||
enableFishIntegration = enabledOption ''
|
||||
Fish integration
|
||||
'';
|
||||
|
||||
direnvrcExtra = lib.mkOption {
|
||||
type = lib.types.lines;
|
||||
default = "";
|
||||
|
@ -34,22 +51,14 @@ in
|
|||
the hiding of direnv logging
|
||||
'';
|
||||
|
||||
loadInNixShell =
|
||||
lib.mkEnableOption ''
|
||||
loadInNixShell = enabledOption ''
|
||||
loading direnv in `nix-shell` `nix shell` or `nix develop`
|
||||
''
|
||||
// {
|
||||
default = true;
|
||||
};
|
||||
'';
|
||||
|
||||
nix-direnv = {
|
||||
enable =
|
||||
(lib.mkEnableOption ''
|
||||
a faster, persistent implementation of use_nix and use_flake, to replace the built-in one
|
||||
'')
|
||||
// {
|
||||
default = true;
|
||||
};
|
||||
enable = enabledOption ''
|
||||
a faster, persistent implementation of use_nix and use_flake, to replace the builtin one
|
||||
'';
|
||||
|
||||
package = lib.mkOption {
|
||||
default = pkgs.nix-direnv.override { nix = config.nix.package; };
|
||||
|
@ -65,7 +74,7 @@ in
|
|||
config = lib.mkIf cfg.enable {
|
||||
|
||||
programs = {
|
||||
zsh.interactiveShellInit = ''
|
||||
zsh.interactiveShellInit = lib.mkIf cfg.enableZshIntegration ''
|
||||
if ${lib.boolToString cfg.loadInNixShell} || printenv PATH | grep -vqc '/nix/store'; then
|
||||
eval "$(${lib.getExe cfg.package} hook zsh)"
|
||||
fi
|
||||
|
@ -73,13 +82,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.package} 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.package} hook fish | source
|
||||
|
@ -88,12 +97,9 @@ in
|
|||
};
|
||||
|
||||
environment = {
|
||||
systemPackages =
|
||||
if cfg.loadInNixShell then
|
||||
[ cfg.package ]
|
||||
else
|
||||
[
|
||||
#direnv has a fish library which sources direnv for some reason
|
||||
systemPackages = [
|
||||
# direnv has a fish library which automatically sources direnv for some reason
|
||||
# I don't see any harm in doing this if we're sourcing it with fish.interactiveShellInit
|
||||
(pkgs.symlinkJoin {
|
||||
inherit (cfg.package) name;
|
||||
paths = [ cfg.package ];
|
||||
|
|
Loading…
Reference in a new issue