From b1bcd7acba553608e44cd4e3d11b92d792d520d3 Mon Sep 17 00:00:00 2001 From: Gabriella Gonzalez Date: Sat, 29 Mar 2025 18:05:23 -0700 Subject: [PATCH] nixos/bash: Add support for `/etc/bash_logout` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- nixos/modules/programs/bash/bash.nix | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/nixos/modules/programs/bash/bash.nix b/nixos/modules/programs/bash/bash.nix index 213f0d2698ae..6acbea562822 100644 --- a/nixos/modules/programs/bash/bash.nix +++ b/nixos/modules/programs/bash/bash.nix @@ -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;