From 450571056552c9311fcb2894328696b535265593 Mon Sep 17 00:00:00 2001 From: Nikita Uvarov Date: Mon, 28 Oct 2019 11:11:44 +0100 Subject: [PATCH] zsh: fix history.path issues - Default value is set to static '$HOME/.zsh_history' -- dotDir is not prepended anymore - $HOME is not prepended to the option value - Ensure history path directory exists Fixes #886, replaces #427. --- doc/release-notes/rl-2003.adoc | 6 ++++- modules/misc/news.nix | 15 ++++++++++++ modules/programs/zsh.nix | 13 ++++++++--- tests/modules/programs/zsh/default.nix | 4 ++++ .../programs/zsh/history-path-new-custom.nix | 23 +++++++++++++++++++ .../programs/zsh/history-path-new-default.nix | 20 ++++++++++++++++ .../programs/zsh/history-path-old-custom.nix | 23 +++++++++++++++++++ .../programs/zsh/history-path-old-default.nix | 20 ++++++++++++++++ 8 files changed, 120 insertions(+), 4 deletions(-) create mode 100644 tests/modules/programs/zsh/history-path-new-custom.nix create mode 100644 tests/modules/programs/zsh/history-path-new-default.nix create mode 100644 tests/modules/programs/zsh/history-path-old-custom.nix create mode 100644 tests/modules/programs/zsh/history-path-old-default.nix diff --git a/doc/release-notes/rl-2003.adoc b/doc/release-notes/rl-2003.adoc index ff6d9325b..b98428dbe 100644 --- a/doc/release-notes/rl-2003.adoc +++ b/doc/release-notes/rl-2003.adoc @@ -18,4 +18,8 @@ The state version in this release includes the changes below. These changes are only active if the `home.stateVersion` option is set to "20.03" or later. -* Nothing has happened. +* The <> option is no longer prepended + by `$HOME`, which allows specifying absolute paths, for example, + using the xdg module. Also, the default value is fixed to + `$HOME/.zsh_history` and `dotDir` path is not prepended to it + anymore. diff --git a/modules/misc/news.nix b/modules/misc/news.nix index bbbe1a047..a00c81ee1 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -1214,6 +1214,21 @@ in A new module is available: 'programs.pazi'. ''; } + + { + time = "2019-11-05T21:54:04+00:00"; + condition = config.programs.zsh.enable; + message = '' + The 'programs.zsh.history.path' option behavior and the + default value has changed for state version 20.03 and above. + + Specifically, '$HOME' will no longer be prepended to the + option value, which allows specifying absolute paths (e.g. + using the xdg module). Also, the default value is fixed to + '$HOME/.zsh_history' and 'dotDir' path is not prepended to + it anymore. + ''; + } ]; }; } diff --git a/modules/programs/zsh.nix b/modules/programs/zsh.nix index ffe5f4960..897d35b0c 100644 --- a/modules/programs/zsh.nix +++ b/modules/programs/zsh.nix @@ -26,6 +26,8 @@ let vicmd = "bindkey -a"; }; + stateVersion = config.home.stateVersion; + historyModule = types.submodule ({ config, ... }: { options = { size = mkOption { @@ -43,8 +45,10 @@ let path = mkOption { type = types.str; - default = relToDotDir ".zsh_history"; - defaultText = ".zsh_history"; + default = if versionAtLeast stateVersion "20.03" + then "$HOME/.zsh_history" + else relToDotDir ".zsh_history"; + example = literalExample ''"''${config.xdg.dataHome}/zsh/zsh_history"''; description = "History file location"; }; @@ -402,8 +406,11 @@ in # History options should be set in .zshrc and after oh-my-zsh sourcing. # See https://github.com/rycee/home-manager/issues/177. HISTSIZE="${toString cfg.history.size}" - HISTFILE="$HOME/${cfg.history.path}" SAVEHIST="${toString cfg.history.save}" + ${if versionAtLeast config.home.stateVersion "20.03" + then ''HISTFILE="${cfg.history.path}"'' + else ''HISTFILE="$HOME/${cfg.history.path}"''} + mkdir -p "$(dirname "$HISTFILE")" setopt HIST_FCNTL_LOCK ${if cfg.history.ignoreDups then "setopt" else "unsetopt"} HIST_IGNORE_DUPS diff --git a/tests/modules/programs/zsh/default.nix b/tests/modules/programs/zsh/default.nix index da5dd5b55..37339598e 100644 --- a/tests/modules/programs/zsh/default.nix +++ b/tests/modules/programs/zsh/default.nix @@ -1,3 +1,7 @@ { zsh-session-variables = ./session-variables.nix; + zsh-history-path-new-default = ./history-path-new-default.nix; + zsh-history-path-new-custom = ./history-path-new-custom.nix; + zsh-history-path-old-default = ./history-path-old-default.nix; + zsh-history-path-old-custom = ./history-path-old-custom.nix; } diff --git a/tests/modules/programs/zsh/history-path-new-custom.nix b/tests/modules/programs/zsh/history-path-new-custom.nix new file mode 100644 index 000000000..6a8c7372d --- /dev/null +++ b/tests/modules/programs/zsh/history-path-new-custom.nix @@ -0,0 +1,23 @@ +{ config, lib, pkgs, ... }: + +with lib; + +{ + config = { + home.stateVersion = "20.03"; + programs.zsh = { + enable = true; + history.path = "$HOME/some/directory/zsh_history"; + }; + + nixpkgs.overlays = [ + (self: super: { + zsh = pkgs.writeScriptBin "dummy-zsh" ""; + }) + ]; + + 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 new file mode 100644 index 000000000..b01bd92d6 --- /dev/null +++ b/tests/modules/programs/zsh/history-path-new-default.nix @@ -0,0 +1,20 @@ +{ config, lib, pkgs, ... }: + +with lib; + +{ + config = { + home.stateVersion = "20.03"; + programs.zsh.enable = true; + + nixpkgs.overlays = [ + (self: super: { + zsh = pkgs.writeScriptBin "dummy-zsh" ""; + }) + ]; + + nmt.script = '' + assertFileRegex home-files/.zshrc '^HISTFILE="$HOME/.zsh_history"$' + ''; + }; +} diff --git a/tests/modules/programs/zsh/history-path-old-custom.nix b/tests/modules/programs/zsh/history-path-old-custom.nix new file mode 100644 index 000000000..672ccc810 --- /dev/null +++ b/tests/modules/programs/zsh/history-path-old-custom.nix @@ -0,0 +1,23 @@ +{ config, lib, pkgs, ... }: + +with lib; + +{ + config = { + home.stateVersion = "19.09"; + programs.zsh = { + enable = true; + history.path = "some/directory/zsh_history"; + }; + + nixpkgs.overlays = [ + (self: super: { + zsh = pkgs.writeScriptBin "dummy-zsh" ""; + }) + ]; + + nmt.script = '' + assertFileRegex home-files/.zshrc '^HISTFILE="$HOME/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 new file mode 100644 index 000000000..a89070c90 --- /dev/null +++ b/tests/modules/programs/zsh/history-path-old-default.nix @@ -0,0 +1,20 @@ +{ config, lib, pkgs, ... }: + +with lib; + +{ + config = { + home.stateVersion = "19.03"; + programs.zsh.enable = true; + + nixpkgs.overlays = [ + (self: super: { + zsh = pkgs.writeScriptBin "dummy-zsh" ""; + }) + ]; + + nmt.script = '' + assertFileRegex home-files/.zshrc '^HISTFILE="$HOME/.zsh_history"$' + ''; + }; +}