From 12ebf21be523eaf6db1f19b5a6b9304e99540961 Mon Sep 17 00:00:00 2001 From: Robert Helgesson Date: Thu, 12 Oct 2017 15:06:51 +0200 Subject: [PATCH] bash: add sessionVariables option --- modules/programs/bash.nix | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/modules/programs/bash.nix b/modules/programs/bash.nix index 25929abf..dce7969f 100644 --- a/modules/programs/bash.nix +++ b/modules/programs/bash.nix @@ -64,6 +64,15 @@ in description = "Shell options to set."; }; + sessionVariables = mkOption { + default = {}; + type = types.attrs; + example = { MAILCHECK = 30; }; + description = '' + Environment variables that will be set for the Bash session. + ''; + }; + shellAliases = mkOption { default = {}; example = { ll = "ls -l"; ".." = "cd .."; }; @@ -112,8 +121,16 @@ in histControlStr = concatStringsSep ":" cfg.historyControl; histIgnoreStr = concatStringsSep ":" cfg.historyIgnore; + # If Bash is the session variable setter then this is the + # attribute set of global session variables, otherwise it is an + # empty set. + globalEnvVars = + optionalAttrs + (config.home.sessionVariableSetter == "bash") + config.home.sessionVariables; + envVarsStr = concatStringsSep "\n" ( - mapAttrsToList export config.home.sessionVariables + mapAttrsToList export (cfg.sessionVariables // globalEnvVars) ); in mkIf cfg.enable { home.file.".bash_profile".text = '' @@ -129,8 +146,7 @@ in home.file.".profile".text = '' # -*- mode: sh -*- - ${optionalString (config.home.sessionVariableSetter == "bash") - envVarsStr} + ${envVarsStr} ${cfg.profileExtra} '';