2016-12-12 22:51:08 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.programs.bash;
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
2024-09-30 15:30:50 +00:00
|
|
|
imports = [
|
|
|
|
(mkRenamedOptionModule [ "programs" "bash" "enableCompletion" ] [ "programs" "bash" "completion" "enable" ])
|
|
|
|
];
|
|
|
|
|
2016-12-12 22:51:08 +00:00
|
|
|
options = {
|
|
|
|
|
|
|
|
programs.bash.enable = mkOption {
|
|
|
|
type = types.bool;
|
2017-07-09 08:16:57 +00:00
|
|
|
default = true;
|
2024-04-14 21:02:32 +00:00
|
|
|
description = "Whether to configure bash as an interactive shell.";
|
2016-12-12 22:51:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
programs.bash.interactiveShellInit = mkOption {
|
|
|
|
default = "";
|
2024-04-14 21:02:32 +00:00
|
|
|
description = "Shell script code called during interactive bash shell initialisation.";
|
2016-12-12 22:51:08 +00:00
|
|
|
type = types.lines;
|
|
|
|
};
|
|
|
|
|
2024-09-30 15:30:50 +00:00
|
|
|
programs.bash.completion = {
|
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Enable bash completion for all interactive bash shells.
|
|
|
|
|
|
|
|
NOTE: This doesn't work with bash 3.2, which is installed by default on macOS by Apple.
|
|
|
|
'';
|
|
|
|
};
|
2017-07-11 18:21:09 +00:00
|
|
|
|
2024-09-30 15:30:50 +00:00
|
|
|
package = mkPackageOption pkgs "bash-completion" { };
|
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
|
2024-09-30 15:30:50 +00:00
|
|
|
] ++ optional cfg.completion.enable cfg.completion.package;
|
2017-05-13 13:32:11 +00:00
|
|
|
|
2024-09-30 15:30:50 +00:00
|
|
|
environment.pathsToLink = optionals cfg.completion.enable
|
2017-05-13 13:32:11 +00:00
|
|
|
[ "/etc/bash_completion.d"
|
|
|
|
"/share/bash-completion/completions"
|
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.
|
|
|
|
|
2017-07-09 08:16:57 +00:00
|
|
|
[ -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-10-24 15:30:34 +00:00
|
|
|
if [ -z "$__NIX_DARWIN_SET_ENVIRONMENT_DONE" ]; then
|
|
|
|
. ${config.system.build.setEnvironment}
|
|
|
|
fi
|
2018-10-17 00:37:12 +00:00
|
|
|
|
|
|
|
# Return early if not running interactively, but after basic nix setup.
|
|
|
|
[[ $- != *i* ]] && return
|
|
|
|
|
|
|
|
# Make bash check its window size after a process completes
|
|
|
|
shopt -s checkwinsize
|
|
|
|
|
2017-10-07 10:39:47 +00:00
|
|
|
${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
|
|
|
|
2024-09-30 15:30:50 +00:00
|
|
|
${optionalString cfg.completion.enable ''
|
2018-10-14 13:39:36 +00:00
|
|
|
if [ "$TERM" != "dumb" ]; then
|
2024-09-30 15:30:50 +00:00
|
|
|
source "${cfg.completion.package}/etc/profile.d/bash_completion.sh"
|
2018-10-14 13:39:36 +00:00
|
|
|
|
|
|
|
nullglobStatus=$(shopt -p nullglob)
|
|
|
|
shopt -s nullglob
|
|
|
|
for p in $NIX_PROFILES; do
|
2019-12-12 07:08:02 +00:00
|
|
|
for m in "$p/etc/bash_completion.d/"*; do
|
2018-10-14 13:39:36 +00:00
|
|
|
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
|
|
|
|
'';
|
|
|
|
|
2020-06-17 16:35:37 +00:00
|
|
|
environment.etc."bashrc".knownSha256Hashes = [
|
2023-06-24 03:23:04 +00:00
|
|
|
"444c716ac2ccd9e1e3347858cb08a00d2ea38e8c12fdc5798380dc261e32e9ef" # macOS
|
|
|
|
"617b39e36fa69270ddbee19ddc072497dbe7ead840cbd442d9f7c22924f116f4" # official Nix installer
|
|
|
|
"6be16cf7c24a3c6f7ae535c913347a3be39508b3426f5ecd413e636e21031e66" # official Nix installer
|
|
|
|
"08ffbf991a9e25839d38b80a0d3bce3b5a6c84b9be53a4b68949df4e7e487bb7" # DeterminateSystems installer
|
2020-06-17 16:35:37 +00:00
|
|
|
];
|
|
|
|
|
2016-12-12 22:51:08 +00:00
|
|
|
};
|
|
|
|
}
|