2.home-manager/tests/modules/programs/zsh/history-path.nix
Kristopher James Kent (kjkent) 9fca491587 zsh: improve histfile handling
Previously, a stateVersion check for 20.03 determined whether or not the input to
`programs.zsh.history.path` would be prepended with `$HOME`. However, this was not
communicated in the documentation, which stated the version check determined whether
the default histfile location would be in `programs.zsh.dotDir` or
`home.homeDirectory`.

The current change simplifies matters and brings path handling in-line with that of
the preceding work on dotDir path handling. If a relative path is provided, it is
parsed as being relative to `home.homeDirectory`. Both absolute and relative paths
are supported, and are cleaned before being passed to other functions.

Tests have been rewritten for the new logic, with case handling for reusability.

Signed-off-by: Austin Horstman <khaneliman12@gmail.com>
2025-07-25 13:15:29 -05:00

41 lines
952 B
Nix

case:
{ config, ... }:
let
homeDir = config.home.homeDirectory;
histfileName = ".zsh_history";
customHistRelPath = "some/subdir/${histfileName}";
customHistAbsPath = "${homeDir}/${customHistRelPath}";
# default option isn't exposed by submodule so this won't reflect
# changes to the the module and may need to be updated in future
defaultHistPath = "${homeDir}/${histfileName}";
testPath =
if case == "absolute" then
customHistAbsPath
else if case == "relative" then
customHistRelPath
else if case == "default" then
defaultHistPath
else
abort "Test condition not provided";
expectedPath = if case == "default" then defaultHistPath else customHistAbsPath;
in
{
config = {
programs.zsh = {
enable = true;
history.path = testPath;
};
test.stubs.zsh = { };
nmt.script = ''
assertFileRegex home-files/.zshrc '^HISTFILE="${expectedPath}"$'
'';
};
}