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:

ee0fecd318/pkgs/shells/bash/5.nix (L48)

… and the `programs.bash.logout` option configures that logout script.
This commit is contained in:
Gabriella Gonzalez 2025-03-29 18:05:23 -07:00 committed by gabby
parent 4e18d2d818
commit b1bcd7acba

View File

@ -111,6 +111,13 @@ in
internal = true;
};
logout = lib.mkOption {
default = "";
description = ''
Shell script code called during login bash shell logout.
'';
type = lib.types.lines;
};
};
};
@ -197,6 +204,21 @@ in
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
'';
# Configuration for readline in bash. We use "option default"
# priority to allow user override using both .text and .source.
environment.etc.inputrc.source = lib.mkOptionDefault ./inputrc;