2009-05-28 13:06:54 +01:00
|
|
|
# This module defines global configuration for the Bash shell, in
|
|
|
|
# particular /etc/bashrc and /etc/profile.
|
|
|
|
|
2010-09-13 16:41:38 +01:00
|
|
|
{ config, pkgs, ... }:
|
|
|
|
|
|
|
|
with pkgs.lib;
|
2009-05-28 13:06:54 +01:00
|
|
|
|
2009-05-28 14:17:56 +01:00
|
|
|
let
|
|
|
|
|
2013-01-30 13:05:53 +00:00
|
|
|
cfg = config.environment;
|
|
|
|
|
|
|
|
initBashCompletion = optionalString cfg.enableBashCompletion ''
|
2012-10-16 17:23:28 +01: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 18:07:19 +01:00
|
|
|
for p in $NIX_PROFILES; do
|
2013-04-10 16:35:05 +01:00
|
|
|
for m in "$p/etc/bash_completion.d/"* "$p/share/bash-completion/completions/"*; do
|
2012-10-16 17:23:28 +01:00
|
|
|
. $m
|
|
|
|
done
|
|
|
|
done
|
|
|
|
eval "$nullglobStatus"
|
2012-10-16 17:41:20 +01:00
|
|
|
unset nullglobStatus p m
|
2012-10-16 17:23:28 +01:00
|
|
|
fi
|
|
|
|
'';
|
|
|
|
|
2012-07-25 15:53:46 +01:00
|
|
|
shellAliases = concatStringsSep "\n" (
|
2013-01-30 13:05:53 +00:00
|
|
|
mapAttrsFlatten (k: v: "alias ${k}='${v}'") cfg.shellAliases
|
2012-07-25 15:53:46 +01:00
|
|
|
);
|
2012-10-16 17:23:28 +01:00
|
|
|
|
2009-05-28 14:17:56 +01:00
|
|
|
options = {
|
|
|
|
|
2013-01-30 13:42:30 +00:00
|
|
|
environment.promptInit = mkOption {
|
2012-11-11 20:29:33 +00:00
|
|
|
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
|
|
|
|
'';
|
2013-01-30 13:05:53 +00:00
|
|
|
description = ''
|
|
|
|
Shell script code used to initialise the shell prompt.
|
|
|
|
'';
|
2012-11-11 20:29:33 +00:00
|
|
|
type = with pkgs.lib.types; string;
|
|
|
|
};
|
2012-10-30 12:33:37 +00:00
|
|
|
|
2010-09-13 16:41:38 +01:00
|
|
|
environment.shellInit = mkOption {
|
2012-11-11 20:29:33 +00:00
|
|
|
default = "";
|
|
|
|
example = ''export PATH=/godi/bin/:$PATH'';
|
2013-01-30 13:05:53 +00:00
|
|
|
description = ''
|
|
|
|
Shell script code called during login shell initialisation.
|
|
|
|
'';
|
|
|
|
type = with pkgs.lib.types; string;
|
|
|
|
};
|
|
|
|
|
|
|
|
environment.interactiveShellInit = mkOption {
|
|
|
|
default = "";
|
|
|
|
example = ''export PATH=/godi/bin/:$PATH'';
|
|
|
|
description = ''
|
|
|
|
Shell script code called during interactive shell initialisation.
|
|
|
|
'';
|
2012-11-11 20:29:33 +00:00
|
|
|
type = with pkgs.lib.types; string;
|
|
|
|
};
|
2009-05-28 14:17:56 +01:00
|
|
|
|
2012-10-16 17:23:28 +01:00
|
|
|
environment.enableBashCompletion = mkOption {
|
2012-11-11 20:29:33 +00:00
|
|
|
default = false;
|
2013-01-30 13:05:53 +00:00
|
|
|
description = "Enable Bash completion for all interactive shells.";
|
2012-11-11 20:29:33 +00:00
|
|
|
type = with pkgs.lib.types; bool;
|
|
|
|
};
|
2012-10-16 17:23:28 +01:00
|
|
|
|
2012-11-11 20:46:25 +00:00
|
|
|
environment.binsh = mkOption {
|
|
|
|
default = "${config.system.build.binsh}/bin/sh";
|
|
|
|
example = "\${pkgs.dash}/bin/dash";
|
|
|
|
type = with pkgs.lib.types; path;
|
|
|
|
description = ''
|
|
|
|
Select the shell executable that is linked system-wide to
|
|
|
|
<literal>/bin/sh</literal>. Please note that NixOS assumes all
|
|
|
|
over the place that shell to be Bash, so override the default
|
|
|
|
setting only if you know exactly what you're doing.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2009-05-28 14:17:56 +01:00
|
|
|
};
|
|
|
|
|
2011-09-14 19:20:50 +01:00
|
|
|
in
|
|
|
|
|
2009-05-28 13:06:54 +01:00
|
|
|
{
|
2009-05-28 14:17:56 +01:00
|
|
|
require = [options];
|
|
|
|
|
2009-05-28 13:06:54 +01:00
|
|
|
environment.etc =
|
2011-09-23 15:21:36 +01:00
|
|
|
[ { # Script executed when the shell starts as a login shell.
|
2009-05-28 13:06:54 +01:00
|
|
|
source = pkgs.substituteAll {
|
2011-09-23 15:21:36 +01:00
|
|
|
src = ./profile.sh;
|
2009-05-28 13:06:54 +01:00
|
|
|
wrapperDir = config.security.wrapperDir;
|
2013-01-30 13:05:53 +00:00
|
|
|
inherit (cfg) shellInit;
|
2009-05-28 13:06:54 +01:00
|
|
|
};
|
|
|
|
target = "profile";
|
|
|
|
}
|
|
|
|
|
2011-09-23 15:21:36 +01:00
|
|
|
{ # /etc/bashrc: executed every time a bash starts. Sources
|
|
|
|
# /etc/profile to ensure that the system environment is
|
|
|
|
# configured properly.
|
2012-07-25 15:53:46 +01:00
|
|
|
source = pkgs.substituteAll {
|
|
|
|
src = ./bashrc.sh;
|
2013-01-30 13:05:53 +00:00
|
|
|
inherit (cfg) interactiveShellInit;
|
2012-07-25 15:53:46 +01:00
|
|
|
};
|
|
|
|
target = "bashrc";
|
2009-05-28 13:06:54 +01:00
|
|
|
}
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2009-05-28 13:06:54 +01:00
|
|
|
{ # Configuration for readline in bash.
|
|
|
|
source = ./inputrc;
|
|
|
|
target = "inputrc";
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2012-11-30 15:12:04 +00:00
|
|
|
environment.shellAliases =
|
|
|
|
{ ls = "ls --color=tty";
|
|
|
|
ll = "ls -l";
|
|
|
|
l = "ls -alh";
|
|
|
|
which = "type -P";
|
|
|
|
};
|
2012-07-25 15:53:46 +01:00
|
|
|
|
2013-01-30 13:05:53 +00:00
|
|
|
environment.interactiveShellInit =
|
|
|
|
''
|
|
|
|
# Check the window size after every command.
|
|
|
|
shopt -s checkwinsize
|
|
|
|
|
|
|
|
${cfg.promptInit}
|
|
|
|
${initBashCompletion}
|
|
|
|
${shellAliases}
|
|
|
|
'';
|
|
|
|
|
2009-05-28 13:06:54 +01:00
|
|
|
system.build.binsh = pkgs.bashInteractive;
|
2010-09-13 16:41:38 +01: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
|
2013-01-30 13:05:53 +00:00
|
|
|
ln -sfn "${cfg.binsh}" /bin/.sh.tmp
|
2012-03-08 16:08:03 +00:00
|
|
|
mv /bin/.sh.tmp /bin/sh # atomically replace /bin/sh
|
2010-09-13 16:41:38 +01:00
|
|
|
'';
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2013-04-10 16:35:05 +01:00
|
|
|
environment.pathsToLink = optionals cfg.enableBashCompletion [
|
|
|
|
"/etc/bash_completion.d"
|
|
|
|
"/share/bash-completion"
|
|
|
|
];
|
2009-05-28 13:06:54 +01:00
|
|
|
}
|