nixos/bash: Add support for `/etc/bash_logout`

This adds a new `programs.bash.logout` option which configures the Bash
logout script.

Carefully note that the stock Bash does not support a global logout
script and only supports user-local logout scripts in `~/.bash_logout`.
However, Nixpkgs patches Bash to support a global `/etc/bash_logout`
script here:

https://github.com/NixOS/nixpkgs/blob/ee0fecd318d77921ecb0f536df98db184a08305d/pkgs/shells/bash/5.nix#L48

… and the `programs.bash.logout` option configures that logout script.

Changed files
+22
nixos
modules
programs
bash
+22
nixos/modules/programs/bash/bash.nix
···
internal = true;
};
+
logout = lib.mkOption {
+
default = "";
+
description = ''
+
Shell script code called during login bash shell logout.
+
'';
+
type = lib.types.lines;
+
};
};
};
···
# Read system-wide modifications.
if test -f /etc/bashrc.local; then
. /etc/bashrc.local
+
fi
+
'';
+
+
environment.etc.bash_logout.text = ''
+
# /etc/bash_logout: DO NOT EDIT -- this file has been generated automatically.
+
+
# Only execute this file once per shell.
+
if [ -n "$__ETC_BASHLOGOUT_SOURCED" ] || [ -n "$NOSYSBASHLOGOUT" ]; then return; fi
+
__ETC_BASHLOGOUT_SOURCED=1
+
+
${cfg.logout}
+
+
# Read system-wide modifications.
+
if test -f /etc/bash_logout.local; then
+
. /etc/bash_logout.local
fi
'';