2016-12-12 22:51:08 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.programs.bash;
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
|
|
|
|
programs.bash.enable = mkOption {
|
|
|
|
type = types.bool;
|
2017-07-09 08:16:57 +00:00
|
|
|
default = true;
|
2017-05-13 13:32:11 +00:00
|
|
|
description = "Whether to configure bash as an interactive shell.";
|
2016-12-12 22:51:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
programs.bash.interactiveShellInit = mkOption {
|
|
|
|
default = "";
|
2017-05-13 13:32:11 +00:00
|
|
|
description = "Shell script code called during interactive bash shell initialisation.";
|
2016-12-12 22:51:08 +00:00
|
|
|
type = types.lines;
|
|
|
|
};
|
|
|
|
|
2017-05-13 13:32:11 +00:00
|
|
|
programs.bash.enableCompletion = mkOption {
|
|
|
|
type = types.bool;
|
2017-07-11 18:21:09 +00:00
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Enable bash completion for all interactive bash shells.
|
|
|
|
|
|
|
|
NOTE. This doesn't work with bash 3.2, which is the default on macOS.
|
|
|
|
'';
|
2017-05-13 13:32:11 +00:00
|
|
|
};
|
|
|
|
|
2016-12-12 22:51:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
|
|
|
environment.systemPackages =
|
|
|
|
[ # Include bash package
|
2017-03-11 21:30:15 +00:00
|
|
|
pkgs.bashInteractive
|
2017-05-13 13:32:11 +00:00
|
|
|
] ++ optional cfg.enableCompletion pkgs.bash-completion;
|
|
|
|
|
|
|
|
environment.pathsToLink =
|
|
|
|
[ "/etc/bash_completion.d"
|
|
|
|
"/share/bash-completion/completions"
|
2016-12-12 22:51:08 +00:00
|
|
|
];
|
|
|
|
|
2018-01-20 00:34:45 +00:00
|
|
|
environment.loginShell = mkDefault "bash -l";
|
|
|
|
environment.variables.SHELL = mkDefault "${pkgs.bashInteractive}/bin/bash";
|
2016-12-12 22:51:08 +00:00
|
|
|
|
|
|
|
environment.etc."bashrc".text = ''
|
|
|
|
# /etc/bashrc: DO NOT EDIT -- this file has been generated automatically.
|
|
|
|
# This file is read for interactive shells.
|
|
|
|
|
2018-10-14 13:38:26 +00:00
|
|
|
# If not running interactively, don't do anything
|
|
|
|
[[ $- != *i* ]] && return
|
|
|
|
|
2017-07-09 08:16:57 +00:00
|
|
|
# Make bash check its window size after a process completes
|
|
|
|
shopt -s checkwinsize
|
|
|
|
|
|
|
|
[ -r "/etc/bashrc_$TERM_PROGRAM" ] && . "/etc/bashrc_$TERM_PROGRAM"
|
|
|
|
|
2016-12-12 22:51:08 +00:00
|
|
|
# Only execute this file once per shell.
|
|
|
|
if [ -n "$__ETC_BASHRC_SOURCED" -o -n "$NOSYSBASHRC" ]; then return; fi
|
|
|
|
__ETC_BASHRC_SOURCED=1
|
|
|
|
|
2018-01-13 13:51:36 +00:00
|
|
|
# Don't execute this file when running in a pure nix-shell.
|
|
|
|
if test -n "$IN_NIX_SHELL"; then return; fi
|
|
|
|
|
2017-05-15 17:22:44 +00:00
|
|
|
export PATH=${config.environment.systemPath}
|
2017-10-07 10:39:47 +00:00
|
|
|
${config.system.build.setEnvironment.text}
|
|
|
|
${config.system.build.setAliases.text}
|
2017-01-08 21:56:16 +00:00
|
|
|
|
|
|
|
${config.environment.interactiveShellInit}
|
|
|
|
${cfg.interactiveShellInit}
|
2016-12-12 22:51:08 +00:00
|
|
|
|
2017-05-13 13:32:11 +00:00
|
|
|
${optionalString cfg.enableCompletion ''
|
2018-10-14 13:39:36 +00:00
|
|
|
if [ "$TERM" != "dumb" ]; then
|
|
|
|
source "${pkgs.bash-completion}/etc/profile.d/bash_completion.sh"
|
|
|
|
|
|
|
|
nullglobStatus=$(shopt -p nullglob)
|
|
|
|
shopt -s nullglob
|
|
|
|
for p in $NIX_PROFILES; do
|
|
|
|
for m in "$p/etc/bash_completion.d/"* "$p/share/bash-completion/completions/"*; do
|
|
|
|
source $m
|
|
|
|
done
|
2017-05-13 13:32:11 +00:00
|
|
|
done
|
2018-10-14 13:39:36 +00:00
|
|
|
eval "$nullglobStatus"
|
|
|
|
unset nullglobStatus p m
|
|
|
|
fi
|
2017-05-13 13:32:11 +00:00
|
|
|
''}
|
|
|
|
|
2016-12-12 22:51:08 +00:00
|
|
|
# Read system-wide modifications.
|
|
|
|
if test -f /etc/bash.local; then
|
2017-05-13 13:32:11 +00:00
|
|
|
source /etc/bash.local
|
2016-12-12 22:51:08 +00:00
|
|
|
fi
|
|
|
|
'';
|
|
|
|
|
|
|
|
};
|
|
|
|
}
|