2009-05-28 14:06:54 +02:00
|
|
|
# This module defines global configuration for the Bash shell, in
|
|
|
|
# particular /etc/bashrc and /etc/profile.
|
|
|
|
|
2010-09-13 17:41:38 +02:00
|
|
|
{ config, pkgs, ... }:
|
|
|
|
|
|
|
|
with pkgs.lib;
|
2009-05-28 14:06:54 +02:00
|
|
|
|
2009-05-28 15:17:56 +02:00
|
|
|
let
|
|
|
|
|
2013-09-18 05:18:34 +02:00
|
|
|
cfge = config.environment;
|
2013-01-30 14:05:53 +01:00
|
|
|
|
2013-09-18 05:18:34 +02:00
|
|
|
cfg = config.programs.bash;
|
|
|
|
|
|
|
|
bashCompletion = optionalString cfg.enableCompletion ''
|
2012-10-16 18:23:28 +02:00
|
|
|
# Check whether we're running a version of Bash that has support for
|
|
|
|
# programmable completion. If we do, enable all modules installed in
|
|
|
|
# the system (and user profile).
|
|
|
|
if shopt -q progcomp &>/dev/null; then
|
|
|
|
. "${pkgs.bashCompletion}/etc/profile.d/bash_completion.sh"
|
|
|
|
nullglobStatus=$(shopt -p nullglob)
|
|
|
|
shopt -s nullglob
|
2012-10-16 19:07:19 +02:00
|
|
|
for p in $NIX_PROFILES; do
|
2013-04-10 17:35:05 +02:00
|
|
|
for m in "$p/etc/bash_completion.d/"* "$p/share/bash-completion/completions/"*; do
|
2012-10-16 18:23:28 +02:00
|
|
|
. $m
|
|
|
|
done
|
|
|
|
done
|
|
|
|
eval "$nullglobStatus"
|
2012-10-16 18:41:20 +02:00
|
|
|
unset nullglobStatus p m
|
2012-10-16 18:23:28 +02:00
|
|
|
fi
|
|
|
|
'';
|
|
|
|
|
2013-09-18 05:18:34 +02:00
|
|
|
bashAliases = concatStringsSep "\n" (
|
2013-01-30 14:05:53 +01:00
|
|
|
mapAttrsFlatten (k: v: "alias ${k}='${v}'") cfg.shellAliases
|
2012-07-25 16:53:46 +02:00
|
|
|
);
|
2012-10-16 18:23:28 +02:00
|
|
|
|
2013-09-04 13:05:09 +02:00
|
|
|
in
|
|
|
|
|
|
|
|
{
|
2009-05-28 15:17:56 +02:00
|
|
|
options = {
|
|
|
|
|
2013-09-18 05:18:34 +02:00
|
|
|
programs.bash = {
|
|
|
|
|
|
|
|
enable = mkOption {
|
|
|
|
default = true;
|
|
|
|
description = ''
|
|
|
|
Whenever to configure Bash as an interactive shell.
|
|
|
|
Note that this tries to make Bash the default
|
|
|
|
<option>users.defaultUserShell</option>,
|
|
|
|
which in turn means that you might need to explicitly
|
|
|
|
set this variable if you have another shell configured
|
|
|
|
with NixOS.
|
|
|
|
'';
|
|
|
|
type = types.bool;
|
|
|
|
};
|
2012-10-30 13:33:37 +01:00
|
|
|
|
2013-09-18 05:18:34 +02:00
|
|
|
shellAliases = mkOption {
|
|
|
|
default = config.environment.shellAliases // { which = "type -P"; };
|
|
|
|
description = ''
|
|
|
|
Set of aliases for bash shell. See <option>environment.shellAliases</option>
|
|
|
|
for an option format description.
|
|
|
|
'';
|
|
|
|
type = types.attrs; # types.attrsOf types.stringOrPath;
|
|
|
|
};
|
2013-01-30 14:05:53 +01:00
|
|
|
|
2013-09-18 05:18:34 +02:00
|
|
|
shellInit = mkOption {
|
|
|
|
default = "";
|
|
|
|
description = ''
|
|
|
|
Shell script code called during bash shell initialisation.
|
|
|
|
'';
|
|
|
|
type = types.lines;
|
|
|
|
};
|
2009-05-28 15:17:56 +02:00
|
|
|
|
2013-09-18 05:18:34 +02:00
|
|
|
loginShellInit = mkOption {
|
|
|
|
default = "";
|
|
|
|
description = ''
|
|
|
|
Shell script code called during login bash shell initialisation.
|
|
|
|
'';
|
|
|
|
type = types.lines;
|
|
|
|
};
|
|
|
|
|
|
|
|
interactiveShellInit = mkOption {
|
|
|
|
default = "";
|
|
|
|
description = ''
|
|
|
|
Shell script code called during interactive bash shell initialisation.
|
|
|
|
'';
|
|
|
|
type = types.lines;
|
|
|
|
};
|
|
|
|
|
|
|
|
promptInit = mkOption {
|
|
|
|
default = ''
|
|
|
|
# Provide a nice prompt.
|
|
|
|
PROMPT_COLOR="1;31m"
|
|
|
|
let $UID && PROMPT_COLOR="1;32m"
|
|
|
|
PS1="\n\[\033[$PROMPT_COLOR\][\u@\h:\w]\\$\[\033[0m\] "
|
|
|
|
if test "$TERM" = "xterm"; then
|
|
|
|
PS1="\[\033]2;\h:\u:\w\007\]$PS1"
|
|
|
|
fi
|
|
|
|
'';
|
|
|
|
description = ''
|
|
|
|
Shell script code used to initialise the bash prompt.
|
|
|
|
'';
|
|
|
|
type = types.lines;
|
|
|
|
};
|
|
|
|
|
|
|
|
enableCompletion = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Enable Bash completion for all interactive bash shells.
|
|
|
|
'';
|
|
|
|
type = types.bool;
|
|
|
|
};
|
2012-10-16 18:23:28 +02:00
|
|
|
|
2012-11-11 21:46:25 +01:00
|
|
|
};
|
|
|
|
|
2009-05-28 15:17:56 +02:00
|
|
|
};
|
|
|
|
|
2013-09-18 05:18:34 +02:00
|
|
|
config = mkIf cfg.enable {
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2013-09-18 05:18:34 +02:00
|
|
|
programs.bash = {
|
2013-09-04 13:05:09 +02:00
|
|
|
|
2013-09-18 05:18:34 +02:00
|
|
|
shellInit = ''
|
|
|
|
. /etc/environment
|
2013-09-04 13:05:09 +02:00
|
|
|
|
2013-09-18 05:18:34 +02:00
|
|
|
${cfge.shellInit}
|
|
|
|
'';
|
2013-09-04 13:05:09 +02:00
|
|
|
|
2013-09-18 05:18:34 +02:00
|
|
|
loginShellInit = cfge.loginShellInit;
|
2013-09-04 13:05:09 +02:00
|
|
|
|
2013-09-18 05:18:34 +02:00
|
|
|
interactiveShellInit = ''
|
|
|
|
${cfge.interactiveShellInit}
|
2013-09-04 13:05:09 +02:00
|
|
|
|
|
|
|
# Check the window size after every command.
|
|
|
|
shopt -s checkwinsize
|
|
|
|
|
|
|
|
# Disable hashing (i.e. caching) of command lookups.
|
|
|
|
set +h
|
2013-09-18 05:18:34 +02:00
|
|
|
|
|
|
|
${cfg.promptInit}
|
|
|
|
${bashCompletion}
|
|
|
|
${bashAliases}
|
2013-09-04 13:05:09 +02:00
|
|
|
'';
|
|
|
|
|
2013-09-18 05:18:34 +02:00
|
|
|
};
|
2013-09-04 13:05:09 +02:00
|
|
|
|
2013-09-18 05:18:34 +02:00
|
|
|
environment.etc."profile".text =
|
2013-09-04 13:05:09 +02:00
|
|
|
''
|
2013-09-18 05:18:34 +02:00
|
|
|
# /etc/profile: DO NOT EDIT -- this file has been generated automatically.
|
|
|
|
# This file is read for login shells.
|
|
|
|
|
|
|
|
# Only execute this file once per shell.
|
|
|
|
if [ -n "$__ETC_PROFILE_SOURCED" ]; then return; fi
|
|
|
|
__ETC_PROFILE_SOURCED=1
|
|
|
|
|
|
|
|
if [ -z "$__BASH_SHELL_INIT_DONE" ]; then
|
|
|
|
__BASH_SHELL_INIT_DONE=1
|
|
|
|
${cfg.shellInit}
|
|
|
|
fi
|
|
|
|
|
|
|
|
${cfg.loginShellInit}
|
|
|
|
|
|
|
|
# Read system-wide modifications.
|
|
|
|
if test -f /etc/profile.local; then
|
|
|
|
. /etc/profile.local
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "''${BASH_VERSION:-}" ]; then
|
|
|
|
. /etc/bashrc
|
|
|
|
fi
|
2013-09-04 13:05:09 +02:00
|
|
|
'';
|
|
|
|
|
2013-09-18 05:18:34 +02:00
|
|
|
environment.etc."bashrc".text =
|
|
|
|
''
|
|
|
|
# /etc/bashrc: DO NOT EDIT -- this file has been generated automatically.
|
|
|
|
|
|
|
|
# Only execute this file once per shell.
|
|
|
|
if [ -n "$__ETC_BASHRC_SOURCED" -o -n "$NOSYSBASHRC" ]; then return; fi
|
|
|
|
__ETC_BASHRC_SOURCED=1
|
|
|
|
|
|
|
|
if [ -z "$__BASH_SHELL_INIT_DONE" ]; then
|
|
|
|
__BASH_SHELL_INIT_DONE=1
|
|
|
|
${cfg.shellInit}
|
|
|
|
fi
|
|
|
|
|
|
|
|
# We are not always an interactive shell.
|
|
|
|
if [ -n "$PS1" ]; then
|
|
|
|
${cfg.interactiveShellInit}
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Read system-wide modifications.
|
|
|
|
if test -f /etc/bashrc.local; then
|
|
|
|
. /etc/bashrc.local
|
|
|
|
fi
|
|
|
|
'';
|
|
|
|
|
|
|
|
# Configuration for readline in bash.
|
|
|
|
environment.etc."inputrc".source = ./inputrc;
|
|
|
|
|
|
|
|
users.defaultUserShell = mkDefault "/run/current-system/sw/bin/bash";
|
|
|
|
|
|
|
|
environment.shells =
|
|
|
|
[ "/run/current-system/sw/bin/bash"
|
|
|
|
"/var/run/current-system/sw/bin/bash"
|
|
|
|
"/run/current-system/sw/bin/sh"
|
|
|
|
"/var/run/current-system/sw/bin/sh"
|
|
|
|
"${pkgs.bashInteractive}/bin/bash"
|
|
|
|
"${pkgs.bashInteractive}/bin/sh"
|
|
|
|
];
|
2009-05-28 14:06:54 +02:00
|
|
|
|
2013-09-04 13:05:09 +02:00
|
|
|
};
|
2012-07-25 16:53:46 +02:00
|
|
|
|
2009-05-28 14:06:54 +02:00
|
|
|
}
|