2009-05-28 13:06:54 +01:00
|
|
|
# This module defines global configuration for the Bash shell, in
|
|
|
|
# particular /etc/bashrc and /etc/profile.
|
|
|
|
|
2014-04-14 15:26:48 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
2010-09-13 16:41:38 +01:00
|
|
|
|
2014-04-14 15:26:48 +01:00
|
|
|
with lib;
|
2009-05-28 13:06:54 +01:00
|
|
|
|
2009-05-28 14:17:56 +01:00
|
|
|
let
|
|
|
|
|
2013-09-18 04:18:34 +01:00
|
|
|
cfge = config.environment;
|
2013-01-30 13:05:53 +00:00
|
|
|
|
2013-09-18 04:18:34 +01:00
|
|
|
cfg = config.programs.bash;
|
|
|
|
|
|
|
|
bashAliases = concatStringsSep "\n" (
|
2018-10-12 14:58:35 +01:00
|
|
|
mapAttrsFlatten (k: v: "alias ${k}=${escapeShellArg v}")
|
2019-04-24 04:48:22 +01:00
|
|
|
(filterAttrs (k: v: v != null) cfg.shellAliases)
|
2012-07-25 15:53:46 +01:00
|
|
|
);
|
2012-10-16 17:23:28 +01:00
|
|
|
|
2013-09-04 12:05:09 +01:00
|
|
|
in
|
|
|
|
|
|
|
|
{
|
2019-12-10 01:51:19 +00:00
|
|
|
imports = [
|
|
|
|
(mkRemovedOptionModule [ "programs" "bash" "enable" ] "")
|
|
|
|
];
|
|
|
|
|
2009-05-28 14:17:56 +01:00
|
|
|
options = {
|
|
|
|
|
2013-09-18 04:18:34 +01:00
|
|
|
programs.bash = {
|
|
|
|
|
2014-04-29 17:57:04 +01:00
|
|
|
/*
|
2013-09-18 04:18:34 +01:00
|
|
|
enable = mkOption {
|
|
|
|
default = true;
|
|
|
|
description = ''
|
|
|
|
Whenever to configure Bash as an interactive shell.
|
|
|
|
Note that this tries to make Bash the default
|
|
|
|
<option>users.defaultUserShell</option>,
|
|
|
|
which in turn means that you might need to explicitly
|
|
|
|
set this variable if you have another shell configured
|
|
|
|
with NixOS.
|
|
|
|
'';
|
|
|
|
type = types.bool;
|
|
|
|
};
|
2014-04-29 17:57:04 +01:00
|
|
|
*/
|
2012-10-30 12:33:37 +00:00
|
|
|
|
2013-09-18 04:18:34 +01:00
|
|
|
shellAliases = mkOption {
|
2018-08-04 04:32:30 +01:00
|
|
|
default = {};
|
2013-09-18 04:18:34 +01:00
|
|
|
description = ''
|
2018-08-04 04:32:30 +01:00
|
|
|
Set of aliases for bash shell, which overrides <option>environment.shellAliases</option>.
|
|
|
|
See <option>environment.shellAliases</option> for an option format description.
|
2013-09-18 04:18:34 +01:00
|
|
|
'';
|
2018-10-12 14:58:35 +01:00
|
|
|
type = with types; attrsOf (nullOr (either str path));
|
2013-09-18 04:18:34 +01:00
|
|
|
};
|
2013-01-30 13:05:53 +00:00
|
|
|
|
2013-09-18 04:18:34 +01:00
|
|
|
shellInit = mkOption {
|
|
|
|
default = "";
|
|
|
|
description = ''
|
|
|
|
Shell script code called during bash shell initialisation.
|
|
|
|
'';
|
|
|
|
type = types.lines;
|
|
|
|
};
|
2009-05-28 14:17:56 +01:00
|
|
|
|
2013-09-18 04:18:34 +01:00
|
|
|
loginShellInit = mkOption {
|
|
|
|
default = "";
|
|
|
|
description = ''
|
|
|
|
Shell script code called during login bash shell initialisation.
|
|
|
|
'';
|
|
|
|
type = types.lines;
|
|
|
|
};
|
|
|
|
|
|
|
|
interactiveShellInit = mkOption {
|
|
|
|
default = "";
|
|
|
|
description = ''
|
|
|
|
Shell script code called during interactive bash shell initialisation.
|
|
|
|
'';
|
|
|
|
type = types.lines;
|
|
|
|
};
|
|
|
|
|
|
|
|
promptInit = mkOption {
|
|
|
|
default = ''
|
2015-11-18 15:24:14 +00:00
|
|
|
# Provide a nice prompt if the terminal supports it.
|
2021-09-04 23:31:07 +01:00
|
|
|
if [ "$TERM" != "dumb" ] || [ -n "$INSIDE_EMACS" ]; then
|
2015-10-14 16:15:11 +01:00
|
|
|
PROMPT_COLOR="1;31m"
|
2021-09-04 23:31:07 +01:00
|
|
|
((UID)) && PROMPT_COLOR="1;32m"
|
|
|
|
if [ -n "$INSIDE_EMACS" ] || [ "$TERM" = "eterm" ] || [ "$TERM" = "eterm-color" ]; then
|
2018-12-17 23:42:41 +00:00
|
|
|
# Emacs term mode doesn't support xterm title escape sequence (\e]0;)
|
|
|
|
PS1="\n\[\033[$PROMPT_COLOR\][\u@\h:\w]\\$\[\033[0m\] "
|
|
|
|
else
|
2019-03-05 12:27:32 +00:00
|
|
|
PS1="\n\[\033[$PROMPT_COLOR\][\[\e]0;\u@\h: \w\a\]\u@\h:\w]\\$\[\033[0m\] "
|
2018-12-17 23:42:41 +00:00
|
|
|
fi
|
2015-10-14 16:15:11 +01:00
|
|
|
if test "$TERM" = "xterm"; then
|
|
|
|
PS1="\[\033]2;\h:\u:\w\007\]$PS1"
|
|
|
|
fi
|
2013-09-18 04:18:34 +01:00
|
|
|
fi
|
|
|
|
'';
|
|
|
|
description = ''
|
|
|
|
Shell script code used to initialise the bash prompt.
|
|
|
|
'';
|
|
|
|
type = types.lines;
|
|
|
|
};
|
|
|
|
|
2021-05-03 19:24:24 +01:00
|
|
|
promptPluginInit = mkOption {
|
|
|
|
default = "";
|
2020-01-28 05:11:43 +00:00
|
|
|
description = ''
|
2021-05-03 19:24:24 +01:00
|
|
|
Shell script code used to initialise bash prompt plugins.
|
2020-01-28 05:11:43 +00:00
|
|
|
'';
|
2021-05-03 19:24:24 +01:00
|
|
|
type = types.lines;
|
|
|
|
internal = true;
|
2020-01-28 05:11:43 +00:00
|
|
|
};
|
|
|
|
|
2012-11-11 20:46:25 +00:00
|
|
|
};
|
|
|
|
|
2009-05-28 14:17:56 +01:00
|
|
|
};
|
|
|
|
|
2014-04-29 17:57:04 +01:00
|
|
|
config = /* mkIf cfg.enable */ {
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2013-09-18 04:18:34 +01:00
|
|
|
programs.bash = {
|
2013-09-04 12:05:09 +01:00
|
|
|
|
2018-08-04 04:32:30 +01:00
|
|
|
shellAliases = mapAttrs (name: mkDefault) cfge.shellAliases;
|
|
|
|
|
2013-09-18 04:18:34 +01:00
|
|
|
shellInit = ''
|
2018-08-29 17:05:48 +01:00
|
|
|
if [ -z "$__NIXOS_SET_ENVIRONMENT_DONE" ]; then
|
|
|
|
. ${config.system.build.setEnvironment}
|
|
|
|
fi
|
2013-09-04 12:05:09 +01:00
|
|
|
|
2013-09-18 04:18:34 +01:00
|
|
|
${cfge.shellInit}
|
|
|
|
'';
|
2013-09-04 12:05:09 +01:00
|
|
|
|
2013-09-18 04:18:34 +01:00
|
|
|
loginShellInit = cfge.loginShellInit;
|
2013-09-04 12:05:09 +01:00
|
|
|
|
2013-09-18 04:18:34 +01:00
|
|
|
interactiveShellInit = ''
|
2013-09-04 12:05:09 +01:00
|
|
|
# Check the window size after every command.
|
|
|
|
shopt -s checkwinsize
|
|
|
|
|
|
|
|
# Disable hashing (i.e. caching) of command lookups.
|
|
|
|
set +h
|
2013-09-18 04:18:34 +01:00
|
|
|
|
|
|
|
${cfg.promptInit}
|
2021-05-03 19:24:24 +01:00
|
|
|
${cfg.promptPluginInit}
|
2013-09-18 04:18:34 +01:00
|
|
|
${bashAliases}
|
2013-10-11 10:55:58 +01:00
|
|
|
|
|
|
|
${cfge.interactiveShellInit}
|
2013-09-04 12:05:09 +01:00
|
|
|
'';
|
|
|
|
|
2013-09-18 04:18:34 +01:00
|
|
|
};
|
2013-09-04 12:05:09 +01:00
|
|
|
|
2019-08-13 22:52:01 +01:00
|
|
|
environment.etc.profile.text =
|
2013-09-04 12:05:09 +01:00
|
|
|
''
|
2013-09-18 04:18:34 +01:00
|
|
|
# /etc/profile: DO NOT EDIT -- this file has been generated automatically.
|
|
|
|
# This file is read for login shells.
|
|
|
|
|
|
|
|
# Only execute this file once per shell.
|
|
|
|
if [ -n "$__ETC_PROFILE_SOURCED" ]; then return; fi
|
|
|
|
__ETC_PROFILE_SOURCED=1
|
|
|
|
|
2013-09-24 23:25:22 +01:00
|
|
|
# Prevent this file from being sourced by interactive non-login child shells.
|
|
|
|
export __ETC_PROFILE_DONE=1
|
2013-09-18 04:18:34 +01:00
|
|
|
|
2013-09-24 23:25:22 +01:00
|
|
|
${cfg.shellInit}
|
2013-09-18 04:18:34 +01:00
|
|
|
${cfg.loginShellInit}
|
|
|
|
|
|
|
|
# Read system-wide modifications.
|
|
|
|
if test -f /etc/profile.local; then
|
2018-08-29 17:05:53 +01:00
|
|
|
. /etc/profile.local
|
2013-09-18 04:18:34 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "''${BASH_VERSION:-}" ]; then
|
2018-08-29 17:05:53 +01:00
|
|
|
. /etc/bashrc
|
2013-09-18 04:18:34 +01:00
|
|
|
fi
|
2013-09-04 12:05:09 +01:00
|
|
|
'';
|
|
|
|
|
2019-08-13 22:52:01 +01:00
|
|
|
environment.etc.bashrc.text =
|
2013-09-18 04:18:34 +01:00
|
|
|
''
|
|
|
|
# /etc/bashrc: DO NOT EDIT -- this file has been generated automatically.
|
|
|
|
|
|
|
|
# Only execute this file once per shell.
|
2021-09-04 23:31:07 +01:00
|
|
|
if [ -n "$__ETC_BASHRC_SOURCED" ] || [ -n "$NOSYSBASHRC" ]; then return; fi
|
2013-09-18 04:18:34 +01:00
|
|
|
__ETC_BASHRC_SOURCED=1
|
|
|
|
|
2013-09-24 23:25:22 +01:00
|
|
|
# If the profile was not loaded in a parent process, source
|
|
|
|
# it. But otherwise don't do it because we don't want to
|
|
|
|
# clobber overridden values of $PATH, etc.
|
|
|
|
if [ -z "$__ETC_PROFILE_DONE" ]; then
|
|
|
|
. /etc/profile
|
2013-09-18 04:18:34 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
# We are not always an interactive shell.
|
|
|
|
if [ -n "$PS1" ]; then
|
2018-08-29 17:05:53 +01:00
|
|
|
${cfg.interactiveShellInit}
|
2013-09-18 04:18:34 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Read system-wide modifications.
|
|
|
|
if test -f /etc/bashrc.local; then
|
2018-08-29 17:05:53 +01:00
|
|
|
. /etc/bashrc.local
|
2013-09-18 04:18:34 +01:00
|
|
|
fi
|
|
|
|
'';
|
|
|
|
|
2017-11-20 11:27:50 +00:00
|
|
|
# Configuration for readline in bash. We use "option default"
|
|
|
|
# priority to allow user override using both .text and .source.
|
2019-08-13 22:52:01 +01:00
|
|
|
environment.etc.inputrc.source = mkOptionDefault ./inputrc;
|
2013-09-18 04:18:34 +01:00
|
|
|
|
2016-06-12 20:03:14 +01:00
|
|
|
users.defaultUserShell = mkDefault pkgs.bashInteractive;
|
2013-09-18 04:18:34 +01:00
|
|
|
|
2013-09-27 00:13:20 +01:00
|
|
|
environment.pathsToLink = optionals cfg.enableCompletion [
|
|
|
|
"/etc/bash_completion.d"
|
|
|
|
"/share/bash-completion"
|
|
|
|
];
|
|
|
|
|
2013-09-18 04:18:34 +01:00
|
|
|
environment.shells =
|
|
|
|
[ "/run/current-system/sw/bin/bash"
|
|
|
|
"/run/current-system/sw/bin/sh"
|
|
|
|
"${pkgs.bashInteractive}/bin/bash"
|
|
|
|
"${pkgs.bashInteractive}/bin/sh"
|
|
|
|
];
|
2009-05-28 13:06:54 +01:00
|
|
|
|
2013-09-04 12:05:09 +01:00
|
|
|
};
|
2012-07-25 15:53:46 +01:00
|
|
|
|
2009-05-28 13:06:54 +01:00
|
|
|
}
|