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