From 93ef6aefce9c2cf5f6a3598a5b263c872cdddfc4 Mon Sep 17 00:00:00 2001 From: Robert Helgesson Date: Tue, 31 Jul 2018 15:48:08 +0200 Subject: [PATCH] direnv: add module --- modules/misc/news.nix | 7 ++++++ modules/modules.nix | 1 + modules/programs/direnv.nix | 50 +++++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 modules/programs/direnv.nix diff --git a/modules/misc/news.nix b/modules/misc/news.nix index aa3d4f73..27580912 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 982dab95..1b8733fc 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 00000000..1f0211a1 --- /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)" + ''; + }; +}