1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-12-24 02:39:48 +01:00

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.
This commit is contained in:
Nikita Uvarov 2019-10-28 11:11:44 +01:00 committed by Robert Helgesson
parent 05dabb7239
commit 4505710565
No known key found for this signature in database
GPG key ID: 36BDAA14C2797E89
8 changed files with 120 additions and 4 deletions

View file

@ -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.

View file

@ -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.
'';
}
];
};
}

View file

@ -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

View file

@ -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;
}

View file

@ -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"$'
'';
};
}

View file

@ -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"$'
'';
};
}

View file

@ -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"$'
'';
};
}

View file

@ -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"$'
'';
};
}