From bc9f3c8413a3aaa01ed959c371c1f9e57515965b Mon Sep 17 00:00:00 2001 From: Austin Horstman Date: Thu, 17 Jul 2025 14:19:11 -0500 Subject: [PATCH] direnv: misc cleanup Signed-off-by: Austin Horstman --- modules/programs/direnv.nix | 151 +++++++++++++++++++----------------- 1 file changed, 78 insertions(+), 73 deletions(-) diff --git a/modules/programs/direnv.nix b/modules/programs/direnv.nix index fd2a57d0..408e5c8a 100644 --- a/modules/programs/direnv.nix +++ b/modules/programs/direnv.nix @@ -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 = ""; }; };