diff --git a/modules/misc/news.nix b/modules/misc/news.nix index aa3d4f73c..27580912c 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -725,6 +725,13 @@ in A new module is available: 'services.status-notifier-watcher'. ''; } + + { + time = "2018-07-31T13:47:06+00:00"; + message = '' + A new module is available: 'programs.direnv'. + ''; + } ]; }; } diff --git a/modules/modules.nix b/modules/modules.nix index 982dab956..1b8733fcf 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -29,6 +29,7 @@ let ./programs/beets.nix ./programs/browserpass.nix ./programs/command-not-found/command-not-found.nix + ./programs/direnv.nix ./programs/eclipse.nix ./programs/emacs.nix ./programs/feh.nix diff --git a/modules/programs/direnv.nix b/modules/programs/direnv.nix new file mode 100644 index 000000000..1f0211a16 --- /dev/null +++ b/modules/programs/direnv.nix @@ -0,0 +1,50 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + + cfg = config.programs.direnv; + +in + +{ + meta.maintainers = [ maintainers.rycee ]; + + options.programs.direnv = { + enable = mkEnableOption "direnv, the environment switcher"; + + enableBashIntegration = mkOption { + default = true; + type = types.bool; + description = '' + Whether to enable Bash integration. + ''; + }; + + enableZshIntegration = mkOption { + default = true; + type = types.bool; + description = '' + Whether to enable Zsh integration. + ''; + }; + }; + + config = mkIf cfg.enable { + home.packages = [ pkgs.direnv ]; + + programs.bash.initExtra = + mkIf cfg.enableBashIntegration ( + # Using mkAfter to make it more likely to appear after other + # manipulations of the prompt. + mkAfter '' + eval "$(${pkgs.direnv}/bin/direnv hook bash)" + '' + ); + + programs.zsh.initExtra = mkIf cfg.enableZshIntegration '' + eval "$(${pkgs.direnv}/bin/direnv hook zsh)" + ''; + }; +}