diff --git a/modules/programs/bash.nix b/modules/programs/bash.nix index 3a367b9e7..8356d8a06 100644 --- a/modules/programs/bash.nix +++ b/modules/programs/bash.nix @@ -180,7 +180,7 @@ in { sessionVarsStr = config.lib.shell.exportAll cfg.sessionVariables; - historyControlStr = concatStringsSep "\n" + historyControlStr = (concatStringsSep "\n" (mapAttrsToList (n: v: "${n}=${v}") ({ HISTFILESIZE = toString cfg.historyFileSize; HISTSIZE = toString cfg.historySize; @@ -190,7 +190,8 @@ in { HISTCONTROL = concatStringsSep ":" cfg.historyControl; } // optionalAttrs (cfg.historyIgnore != [ ]) { HISTIGNORE = escapeShellArg (concatStringsSep ":" cfg.historyIgnore); - })); + }) ++ optional (cfg.historyFile != null) + ''mkdir -p "$(dirname "$HISTFILE")"'')); in mkIf cfg.enable { home.packages = [ cfg.package ]; diff --git a/tests/modules/programs/bash/bash-history-control-with-file.nix b/tests/modules/programs/bash/bash-history-control-with-file.nix new file mode 100644 index 000000000..449da8860 --- /dev/null +++ b/tests/modules/programs/bash/bash-history-control-with-file.nix @@ -0,0 +1,20 @@ +{ config, lib, pkgs, ... }: + +with lib; + +{ + config = { + programs.bash = { + enable = true; + historyControl = [ "erasedups" ]; + historyFile = "/home/hm-user/foo/bash/history"; + }; + + nmt.script = '' + assertFileExists home-files/.bashrc + + assertFileRegex home-files/.bashrc \ + '^mkdir -p "\$(dirname "\$HISTFILE")"' + ''; + }; +} diff --git a/tests/modules/programs/bash/default.nix b/tests/modules/programs/bash/default.nix index 1dbbee777..6b20d1fbc 100644 --- a/tests/modules/programs/bash/default.nix +++ b/tests/modules/programs/bash/default.nix @@ -2,4 +2,5 @@ bash-completion = ./completion.nix; bash-logout = ./logout.nix; bash-session-variables = ./session-variables.nix; + bash-history-control-with-file = ./bash-history-control-with-file.nix; }