aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikita Uvarov <uv.nikita@gmail.com>2019-10-28 11:11:44 +0100
committerRobert Helgesson <robert@rycee.net>2019-11-05 23:04:06 +0100
commit450571056552c9311fcb2894328696b535265593 (patch)
tree1e998fe3d050c54d8caabb3f9df2a020edfd6c4f
parent05dabb7239254c0d9b2f314d7aa73923917bd1cd (diff)
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.
-rw-r--r--doc/release-notes/rl-2003.adoc6
-rw-r--r--modules/misc/news.nix15
-rw-r--r--modules/programs/zsh.nix13
-rw-r--r--tests/modules/programs/zsh/default.nix4
-rw-r--r--tests/modules/programs/zsh/history-path-new-custom.nix23
-rw-r--r--tests/modules/programs/zsh/history-path-new-default.nix20
-rw-r--r--tests/modules/programs/zsh/history-path-old-custom.nix23
-rw-r--r--tests/modules/programs/zsh/history-path-old-default.nix20
8 files changed, 120 insertions, 4 deletions
diff --git a/doc/release-notes/rl-2003.adoc b/doc/release-notes/rl-2003.adoc
index ff6d9325bd7..b98428dbe47 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 <<opt-programs.zsh.history.path>> 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 bbbe1a04750..a00c81ee1d8 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 ffe5f4960b6..897d35b0c10 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 da5dd5b55ed..37339598e35 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 00000000000..6a8c7372d34
--- /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 00000000000..b01bd92d67e
--- /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 00000000000..672ccc81002
--- /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 00000000000..a89070c9014
--- /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"$'
+ '';
+ };
+}