1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2024-12-14 11:57:55 +00:00

direnv: add package options

This commit is contained in:
Ramses 2023-09-29 12:51:58 +02:00 committed by GitHub
parent 2ccb5cb542
commit 4f02e35f9d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -24,6 +24,8 @@ in {
options.programs.direnv = { options.programs.direnv = {
enable = mkEnableOption "direnv, the environment switcher"; enable = mkEnableOption "direnv, the environment switcher";
package = mkPackageOption pkgs "direnv" { };
config = mkOption { config = mkOption {
type = tomlFormat.type; type = tomlFormat.type;
default = { }; default = { };
@ -89,12 +91,14 @@ in {
enable = mkEnableOption '' enable = mkEnableOption ''
[nix-direnv](https://github.com/nix-community/nix-direnv), [nix-direnv](https://github.com/nix-community/nix-direnv),
a fast, persistent use_nix implementation for direnv''; a fast, persistent use_nix implementation for direnv'';
package = mkPackageOption pkgs "nix-direnv" { };
}; };
}; };
config = mkIf cfg.enable { config = mkIf cfg.enable {
home.packages = [ pkgs.direnv ]; home.packages = [ cfg.package ];
xdg.configFile."direnv/direnv.toml" = mkIf (cfg.config != { }) { xdg.configFile."direnv/direnv.toml" = mkIf (cfg.config != { }) {
source = tomlFormat.generate "direnv-config" cfg.config; source = tomlFormat.generate "direnv-config" cfg.config;
@ -103,25 +107,25 @@ in {
xdg.configFile."direnv/direnvrc" = let xdg.configFile."direnv/direnvrc" = let
text = concatStringsSep "\n" (optional (cfg.stdlib != "") cfg.stdlib text = concatStringsSep "\n" (optional (cfg.stdlib != "") cfg.stdlib
++ optional cfg.nix-direnv.enable ++ optional cfg.nix-direnv.enable
"source ${pkgs.nix-direnv}/share/nix-direnv/direnvrc"); "source ${cfg.nix-direnv.package}/share/nix-direnv/direnvrc");
in mkIf (text != "") { inherit text; }; in mkIf (text != "") { inherit text; };
programs.bash.initExtra = mkIf cfg.enableBashIntegration ( programs.bash.initExtra = mkIf cfg.enableBashIntegration (
# Using mkAfter to make it more likely to appear after other # Using mkAfter to make it more likely to appear after other
# manipulations of the prompt. # manipulations of the prompt.
mkAfter '' mkAfter ''
eval "$(${pkgs.direnv}/bin/direnv hook bash)" eval "$(${cfg.package}/bin/direnv hook bash)"
''); '');
programs.zsh.initExtra = mkIf cfg.enableZshIntegration '' programs.zsh.initExtra = mkIf cfg.enableZshIntegration ''
eval "$(${pkgs.direnv}/bin/direnv hook zsh)" eval "$(${cfg.package}/bin/direnv hook zsh)"
''; '';
programs.fish.interactiveShellInit = mkIf cfg.enableFishIntegration ( programs.fish.interactiveShellInit = mkIf cfg.enableFishIntegration (
# Using mkAfter to make it more likely to appear after other # Using mkAfter to make it more likely to appear after other
# manipulations of the prompt. # manipulations of the prompt.
mkAfter '' mkAfter ''
${pkgs.direnv}/bin/direnv hook fish | source ${cfg.package}/bin/direnv hook fish | source
''); '');
programs.nushell.extraConfig = mkIf cfg.enableNushellIntegration ( programs.nushell.extraConfig = mkIf cfg.enableNushellIntegration (
@ -133,7 +137,7 @@ in {
$env.config = ($env.config | update hooks ($env.config.hooks | default [] pre_prompt)) $env.config = ($env.config | update hooks ($env.config.hooks | default [] pre_prompt))
$env.config = ($env.config | update hooks.pre_prompt ($env.config.hooks.pre_prompt | append { $env.config = ($env.config | update hooks.pre_prompt ($env.config.hooks.pre_prompt | append {
code: " code: "
let direnv = (${pkgs.direnv}/bin/direnv export json | from json) let direnv = (${cfg.package}/bin/direnv export json | from json)
let direnv = if not ($direnv | is-empty) { $direnv } else { {} } let direnv = if not ($direnv | is-empty) { $direnv } else { {} }
$direnv | load-env $direnv | load-env
" "