Skip to content

Commit

Permalink
bash: Make sure HISTFILE's directory exists
Browse files Browse the repository at this point in the history
Co-authored-by: Robert Helgesson <robert@rycee.net>
  • Loading branch information
DamienCassou and rycee committed Jan 26, 2025
1 parent daf04c5 commit 9c063b0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
5 changes: 3 additions & 2 deletions modules/programs/bash.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 ];

Expand Down
20 changes: 20 additions & 0 deletions tests/modules/programs/bash/bash-history-control-with-file.nix
Original file line number Diff line number Diff line change
@@ -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")"'
'';
};
}
1 change: 1 addition & 0 deletions tests/modules/programs/bash/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 9c063b0

Please sign in to comment.