1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2025-12-02 23:21:02 +01:00

direnv: misc cleanup

Signed-off-by: Austin Horstman <khaneliman12@gmail.com>
This commit is contained in:
Austin Horstman 2025-07-17 14:19:11 -05:00
parent 8320333a45
commit bc9f3c8413

View file

@ -52,7 +52,7 @@ in
package = mkPackageOption pkgs "direnv" { };
config = mkOption {
type = tomlFormat.type;
inherit (tomlFormat) type;
default = { };
description = ''
Configuration written to
@ -126,80 +126,85 @@ in
mkIf cfg.enable {
home.packages = [ cfg.package ];
programs.direnv.config = {
global = mkIf (cfg.silent && isVersion236orHigher) {
log_format = "-";
log_filter = "^$";
programs = {
direnv.config = {
global = mkIf (cfg.silent && isVersion236orHigher) {
log_format = "-";
log_filter = "^$";
};
};
bash.initExtra = mkIf cfg.enableBashIntegration (
# Using `mkAfter` to make it more likely to appear after other
# manipulations of the prompt.
mkAfter ''
eval "$(${getExe cfg.package} hook bash)"
''
);
fish.interactiveShellInit = mkIf cfg.enableFishIntegration (
# Using `mkAfter` to make it more likely to appear after other
# manipulations of the prompt.
mkAfter ''
${getExe cfg.package} hook fish | source
''
);
zsh.initContent = mkIf cfg.enableZshIntegration ''
eval "$(${getExe cfg.package} hook zsh)"
'';
# Using `mkAfter` to make it more likely to appear after other
# manipulations of the prompt.
nushell.extraConfig = mkIf cfg.enableNushellIntegration (mkAfter ''
$env.config = ($env.config? | default {})
$env.config.hooks = ($env.config.hooks? | default {})
$env.config.hooks.pre_prompt = (
$env.config.hooks.pre_prompt?
| default []
| append {||
${getExe cfg.package} export json
| from json --strict
| default {}
| items {|key, value|
let value = do (
{
"PATH": {
from_string: {|s| $s | split row (char esep) | path expand --no-symlink }
to_string: {|v| $v | path expand --no-symlink | str join (char esep) }
}
}
| merge ($env.ENV_CONVERSIONS? | default {})
| get ([[value, optional, insensitive]; [$key, true, true]] | into cell-path)
| get from_string?
| if ($in | is-empty) { {|x| $x} } else { $in }
) $value
return [ $key $value ]
}
| into record
| load-env
}
)
'');
};
xdg.configFile = {
"direnv/direnv.toml" = mkIf (cfg.config != { }) {
source = tomlFormat.generate "direnv-config" cfg.config;
};
"direnv/lib/hm-nix-direnv.sh" = mkIf cfg.nix-direnv.enable {
source = "${cfg.nix-direnv.package}/share/nix-direnv/direnvrc";
};
"direnv/direnvrc" = lib.mkIf (cfg.stdlib != "") { text = cfg.stdlib; };
"direnv/lib/hm-mise.sh" = mkIf cfg.mise.enable {
text = ''
eval "$(${getExe cfg.mise.package} direnv activate)"
'';
};
};
xdg.configFile."direnv/direnv.toml" = mkIf (cfg.config != { }) {
source = tomlFormat.generate "direnv-config" cfg.config;
};
xdg.configFile."direnv/lib/hm-nix-direnv.sh" = mkIf cfg.nix-direnv.enable {
source = "${cfg.nix-direnv.package}/share/nix-direnv/direnvrc";
};
xdg.configFile."direnv/direnvrc" = lib.mkIf (cfg.stdlib != "") { text = cfg.stdlib; };
xdg.configFile."direnv/lib/hm-mise.sh" = mkIf cfg.mise.enable {
text = ''
eval "$(${getExe cfg.mise.package} direnv activate)"
'';
};
programs.bash.initExtra = mkIf cfg.enableBashIntegration (
# Using mkAfter to make it more likely to appear after other
# manipulations of the prompt.
mkAfter ''
eval "$(${getExe cfg.package} hook bash)"
''
);
programs.zsh.initContent = mkIf cfg.enableZshIntegration ''
eval "$(${getExe cfg.package} hook zsh)"
'';
programs.fish.interactiveShellInit = mkIf cfg.enableFishIntegration (
# Using mkAfter to make it more likely to appear after other
# manipulations of the prompt.
mkAfter ''
${getExe cfg.package} hook fish | source
''
);
# Using mkAfter to make it more likely to appear after other
# manipulations of the prompt.
programs.nushell.extraConfig = mkIf cfg.enableNushellIntegration (mkAfter ''
$env.config = ($env.config? | default {})
$env.config.hooks = ($env.config.hooks? | default {})
$env.config.hooks.pre_prompt = (
$env.config.hooks.pre_prompt?
| default []
| append {||
${getExe cfg.package} export json
| from json --strict
| default {}
| items {|key, value|
let value = do (
{
"PATH": {
from_string: {|s| $s | split row (char esep) | path expand --no-symlink }
to_string: {|v| $v | path expand --no-symlink | str join (char esep) }
}
}
| merge ($env.ENV_CONVERSIONS? | default {})
| get ([[value, optional, insensitive]; [$key, true, true]] | into cell-path)
| get from_string?
| if ($in | is-empty) { {|x| $x} } else { $in }
) $value
return [ $key $value ]
}
| into record
| load-env
}
)
'');
home.sessionVariables = lib.mkIf (cfg.silent && !isVersion236orHigher) { DIRENV_LOG_FORMAT = ""; };
};