diff --git a/modules/programs/zsh/history.nix b/modules/programs/zsh/history.nix index 548146879..d32d5da66 100644 --- a/modules/programs/zsh/history.nix +++ b/modules/programs/zsh/history.nix @@ -8,9 +8,8 @@ let cfg = config.programs.zsh; inherit (lib) literalExpression mkOption types; - inherit (config.home) stateVersion; - relToDotDir = file: (lib.optionalString (cfg.dotDir != null) (cfg.dotDir + "/")) + file; + inherit (import ./lib.nix { inherit config lib; }) dotDirAbs mkAbsPathStr; in { options = @@ -49,16 +48,9 @@ in path = mkOption { type = types.str; - default = - if lib.versionAtLeast stateVersion "20.03" then - "$HOME/.zsh_history" - else - relToDotDir ".zsh_history"; - defaultText = literalExpression '' - "$HOME/.zsh_history" if state version ≥ 20.03, - "$ZDOTDIR/.zsh_history" otherwise - ''; - example = literalExpression ''"''${config.xdg.dataHome}/zsh/zsh_history"''; + default = "${dotDirAbs}/.zsh_history"; + defaultText = "`\${config.programs.zsh.dotDir}/.zsh_history`"; + example = "`\${config.xdg.dataHome}/zsh/zsh_history`"; description = "History file location"; }; @@ -188,12 +180,7 @@ in ${lib.optionalString ( cfg.history.ignorePatterns != [ ] ) "HISTORY_IGNORE=${lib.escapeShellArg "(${lib.concatStringsSep "|" cfg.history.ignorePatterns})"}"} - ${ - if lib.versionAtLeast stateVersion "20.03" then - ''HISTFILE="${cfg.history.path}"'' - else - ''HISTFILE="$HOME/${cfg.history.path}"'' - } + HISTFILE="${mkAbsPathStr cfg.history.path}" mkdir -p "$(dirname "$HISTFILE")" setopt HIST_FCNTL_LOCK diff --git a/tests/modules/programs/zsh/aliases.nix b/tests/modules/programs/zsh/aliases.nix index abe44dcf2..906bb62d0 100644 --- a/tests/modules/programs/zsh/aliases.nix +++ b/tests/modules/programs/zsh/aliases.nix @@ -28,7 +28,7 @@ HISTSIZE="10000" SAVEHIST="10000" - HISTFILE="$HOME/.zsh_history" + HISTFILE="/home/hm-user/.zsh_history" mkdir -p "$(dirname "$HISTFILE")" setopt HIST_FCNTL_LOCK diff --git a/tests/modules/programs/zsh/default.nix b/tests/modules/programs/zsh/default.nix index f73cdb66b..d3e3fdd42 100644 --- a/tests/modules/programs/zsh/default.nix +++ b/tests/modules/programs/zsh/default.nix @@ -5,10 +5,9 @@ zsh-dotdir-default = import ./dotdir.nix "default"; zsh-dotdir-relative = import ./dotdir.nix "relative"; zsh-history-ignore-pattern = ./history-ignore-pattern.nix; - zsh-history-path-new-custom = ./history-path-new-custom.nix; - zsh-history-path-new-default = ./history-path-new-default.nix; - zsh-history-path-old-default = ./history-path-old-default.nix; - zsh-history-path-old-custom = ./history-path-old-custom.nix; + zsh-history-path-absolute = import ./history-path.nix "absolute"; + zsh-history-path-default = import ./history-path.nix "default"; + zsh-history-path-relative = import ./history-path.nix "relative"; zsh-history-substring-search = ./history-substring-search.nix; zsh-plugins = ./plugins.nix; zsh-prezto = ./prezto.nix; diff --git a/tests/modules/programs/zsh/history-path-new-custom.nix b/tests/modules/programs/zsh/history-path-new-custom.nix deleted file mode 100644 index 497796186..000000000 --- a/tests/modules/programs/zsh/history-path-new-custom.nix +++ /dev/null @@ -1,11 +0,0 @@ -{ - home.stateVersion = "20.03"; - programs.zsh = { - enable = true; - history.path = "$HOME/some/directory/zsh_history"; - }; - - nmt.script = '' - assertFileRegex home-files/.zshrc '^HISTFILE="$HOME/some/directory/zsh_history"$' - ''; -} diff --git a/tests/modules/programs/zsh/history-path-new-default.nix b/tests/modules/programs/zsh/history-path-new-default.nix deleted file mode 100644 index 813239fad..000000000 --- a/tests/modules/programs/zsh/history-path-new-default.nix +++ /dev/null @@ -1,9 +0,0 @@ -{ - home.stateVersion = "20.03"; - programs.zsh.enable = true; - - nmt.script = '' - assertFileRegex home-files/.zshrc \ - '^HISTFILE="${config.home.homeDirectory}/.zsh_history"$' - ''; -} diff --git a/tests/modules/programs/zsh/history-path-old-custom.nix b/tests/modules/programs/zsh/history-path-old-custom.nix deleted file mode 100644 index 0b8fa451d..000000000 --- a/tests/modules/programs/zsh/history-path-old-custom.nix +++ /dev/null @@ -1,12 +0,0 @@ -{ - home.stateVersion = "19.09"; - programs.zsh = { - enable = true; - history.path = "some/directory/zsh_history"; - }; - - nmt.script = '' - assertFileRegex home-files/.zshrc \ - '^HISTFILE="${config.home.homeDirectory}/some/directory/zsh_history"$' - ''; -} diff --git a/tests/modules/programs/zsh/history-path-old-default.nix b/tests/modules/programs/zsh/history-path-old-default.nix deleted file mode 100644 index e2a7a3848..000000000 --- a/tests/modules/programs/zsh/history-path-old-default.nix +++ /dev/null @@ -1,9 +0,0 @@ -{ - home.stateVersion = "19.03"; - programs.zsh.enable = true; - - nmt.script = '' - assertFileRegex home-files/.zshrc \ - '^HISTFILE="${config.home.homeDirectory}/.zsh_history"$' - ''; -} diff --git a/tests/modules/programs/zsh/history-path.nix b/tests/modules/programs/zsh/history-path.nix new file mode 100644 index 000000000..5db40534a --- /dev/null +++ b/tests/modules/programs/zsh/history-path.nix @@ -0,0 +1,41 @@ +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}"$' + ''; + }; +} diff --git a/tests/modules/programs/zsh/zshrc-content-priorities.nix b/tests/modules/programs/zsh/zshrc-content-priorities.nix index aac0daf40..1d80db940 100644 --- a/tests/modules/programs/zsh/zshrc-content-priorities.nix +++ b/tests/modules/programs/zsh/zshrc-content-priorities.nix @@ -46,7 +46,7 @@ HISTSIZE="10000" SAVEHIST="10000" - HISTFILE="$HOME/.zsh_history" + HISTFILE="/home/hm-user/.zsh_history" mkdir -p "$(dirname "$HISTFILE")" setopt HIST_FCNTL_LOCK