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
|
|
|
|
|
2012-10-16 18:23:28 +02: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 19:07:19 +02:00
|
|
|
for p in $NIX_PROFILES; do
|
2012-10-16 18:23:28 +02:00
|
|
|
for m in "$p/etc/bash_completion.d/"*; do
|
|
|
|
. $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
|
|
|
|
'';
|
|
|
|
|
|
|
|
|
2009-05-28 15:17:56 +02:00
|
|
|
options = {
|
|
|
|
|
2010-09-13 17:41:38 +02:00
|
|
|
environment.shellInit = mkOption {
|
2009-05-28 15:17:56 +02:00
|
|
|
default = "";
|
|
|
|
example = ''export PATH=/godi/bin/:$PATH'';
|
|
|
|
description = "
|
|
|
|
Script used to initialized user shell environments.
|
|
|
|
";
|
2011-12-29 01:51:35 +01:00
|
|
|
type = with pkgs.lib.types; string;
|
2009-05-28 15:17:56 +02:00
|
|
|
};
|
|
|
|
|
2012-10-16 18:23:28 +02:00
|
|
|
environment.enableBashCompletion = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = "Enable bash-completion for all interactive shells.";
|
|
|
|
type = with pkgs.lib.types; bool;
|
|
|
|
};
|
|
|
|
|
2009-05-28 15:17:56 +02:00
|
|
|
};
|
|
|
|
|
2011-09-14 20:20:50 +02:00
|
|
|
in
|
|
|
|
|
2009-05-28 14:06:54 +02:00
|
|
|
{
|
2009-05-28 15:17:56 +02:00
|
|
|
require = [options];
|
|
|
|
|
2009-05-28 14:06:54 +02:00
|
|
|
environment.etc =
|
2011-09-23 16:21:36 +02:00
|
|
|
[ { # Script executed when the shell starts as a login shell.
|
2009-05-28 14:06:54 +02:00
|
|
|
source = pkgs.substituteAll {
|
2011-09-23 16:21:36 +02:00
|
|
|
src = ./profile.sh;
|
2009-05-28 14:06:54 +02:00
|
|
|
wrapperDir = config.security.wrapperDir;
|
|
|
|
shellInit = config.environment.shellInit;
|
|
|
|
};
|
|
|
|
target = "profile";
|
|
|
|
}
|
|
|
|
|
2011-09-23 16:21:36 +02:00
|
|
|
{ # /etc/bashrc: executed every time a bash starts. Sources
|
|
|
|
# /etc/profile to ensure that the system environment is
|
|
|
|
# configured properly.
|
2012-10-16 18:23:28 +02:00
|
|
|
source = pkgs.substituteAll {
|
|
|
|
src = ./bashrc.sh;
|
|
|
|
inherit initBashCompletion;
|
|
|
|
};
|
2011-09-23 16:21:36 +02:00
|
|
|
target = "bashrc";
|
2009-05-28 14:06:54 +02:00
|
|
|
}
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2009-05-28 14:06:54 +02:00
|
|
|
{ # Configuration for readline in bash.
|
|
|
|
source = ./inputrc;
|
|
|
|
target = "inputrc";
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
system.build.binsh = pkgs.bashInteractive;
|
2010-09-13 17:41:38 +02: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 17:08:03 +01: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 17:41:38 +02:00
|
|
|
'';
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2012-10-16 18:23:28 +02:00
|
|
|
environment.pathsToLink = optional config.environment.enableBashCompletion "/etc/bash_completion.d";
|
2009-05-28 14:06:54 +02:00
|
|
|
}
|