2009-05-28 12:06:54 +00:00
|
|
|
# This module defines global configuration for the Bash shell, in
|
|
|
|
# particular /etc/bashrc and /etc/profile.
|
|
|
|
|
2010-09-13 15:41:38 +00:00
|
|
|
{ config, pkgs, ... }:
|
|
|
|
|
|
|
|
with pkgs.lib;
|
2009-05-28 12:06:54 +00:00
|
|
|
|
2009-05-28 13:17:56 +00:00
|
|
|
let
|
|
|
|
|
2012-10-16 16:23:28 +00:00
|
|
|
initBashCompletion = optionalString config.environment.enableBashCompletion ''
|
|
|
|
# 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 17:07:19 +00:00
|
|
|
for p in $NIX_PROFILES; do
|
2012-10-16 16:23:28 +00:00
|
|
|
for m in "$p/etc/bash_completion.d/"*; do
|
|
|
|
. $m
|
|
|
|
done
|
|
|
|
done
|
|
|
|
eval "$nullglobStatus"
|
2012-10-16 16:41:20 +00:00
|
|
|
unset nullglobStatus p m
|
2012-10-16 16:23:28 +00:00
|
|
|
fi
|
|
|
|
'';
|
|
|
|
|
2009-05-28 13:17:56 +00:00
|
|
|
options = {
|
|
|
|
|
2012-10-30 12:33:37 +00:00
|
|
|
environment.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 = "
|
|
|
|
Script used to initialized shell prompt.
|
|
|
|
";
|
|
|
|
type = with pkgs.lib.types; string;
|
|
|
|
};
|
|
|
|
|
2010-09-13 15:41:38 +00:00
|
|
|
environment.shellInit = mkOption {
|
2009-05-28 13:17:56 +00:00
|
|
|
default = "";
|
|
|
|
example = ''export PATH=/godi/bin/:$PATH'';
|
|
|
|
description = "
|
|
|
|
Script used to initialized user shell environments.
|
|
|
|
";
|
2011-12-29 00:51:35 +00:00
|
|
|
type = with pkgs.lib.types; string;
|
2009-05-28 13:17:56 +00:00
|
|
|
};
|
|
|
|
|
2012-10-16 16:23:28 +00:00
|
|
|
environment.enableBashCompletion = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = "Enable bash-completion for all interactive shells.";
|
|
|
|
type = with pkgs.lib.types; bool;
|
|
|
|
};
|
|
|
|
|
2009-05-28 13:17:56 +00:00
|
|
|
};
|
|
|
|
|
2011-09-14 18:20:50 +00:00
|
|
|
in
|
|
|
|
|
2009-05-28 12:06:54 +00:00
|
|
|
{
|
2009-05-28 13:17:56 +00:00
|
|
|
require = [options];
|
|
|
|
|
2009-05-28 12:06:54 +00:00
|
|
|
environment.etc =
|
2011-09-23 14:21:36 +00:00
|
|
|
[ { # Script executed when the shell starts as a login shell.
|
2009-05-28 12:06:54 +00:00
|
|
|
source = pkgs.substituteAll {
|
2011-09-23 14:21:36 +00:00
|
|
|
src = ./profile.sh;
|
2009-05-28 12:06:54 +00:00
|
|
|
wrapperDir = config.security.wrapperDir;
|
|
|
|
shellInit = config.environment.shellInit;
|
|
|
|
};
|
|
|
|
target = "profile";
|
|
|
|
}
|
|
|
|
|
2011-09-23 14:21:36 +00:00
|
|
|
{ # /etc/bashrc: executed every time a bash starts. Sources
|
|
|
|
# /etc/profile to ensure that the system environment is
|
|
|
|
# configured properly.
|
2012-10-16 16:23:28 +00:00
|
|
|
source = pkgs.substituteAll {
|
|
|
|
src = ./bashrc.sh;
|
2012-10-30 12:33:37 +00:00
|
|
|
inherit (config.environment) promptInit;
|
2012-10-16 16:23:28 +00:00
|
|
|
inherit initBashCompletion;
|
|
|
|
};
|
2011-09-23 14:21:36 +00:00
|
|
|
target = "bashrc";
|
2009-05-28 12:06:54 +00:00
|
|
|
}
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2009-05-28 12:06:54 +00:00
|
|
|
{ # Configuration for readline in bash.
|
|
|
|
source = ./inputrc;
|
|
|
|
target = "inputrc";
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
system.build.binsh = pkgs.bashInteractive;
|
2010-09-13 15:41:38 +00:00
|
|
|
|
|
|
|
system.activationScripts.binsh = stringAfter [ "stdio" ]
|
|
|
|
''
|
|
|
|
# Create the required /bin/sh symlink; otherwise lots of things
|
|
|
|
# (notably the system() function) won't work.
|
|
|
|
mkdir -m 0755 -p /bin
|
2012-03-08 16:08:03 +00:00
|
|
|
ln -sfn ${config.system.build.binsh}/bin/sh /bin/.sh.tmp
|
|
|
|
mv /bin/.sh.tmp /bin/sh # atomically replace /bin/sh
|
2010-09-13 15:41:38 +00:00
|
|
|
'';
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2012-10-16 16:23:28 +00:00
|
|
|
environment.pathsToLink = optional config.environment.enableBashCompletion "/etc/bash_completion.d";
|
2009-05-28 12:06:54 +00:00
|
|
|
}
|