Skip to content

Commit

Permalink
modules/home-manager: fix zsh history renaming bug with persist
Browse files Browse the repository at this point in the history
zsh would try to merge history files by "renaming" `$HISTFILE.new` onto
`$HISTFILE`. Since the file was a bind mount, this operation would fail.

Although it never caused much problems given that originally this merge
seemed to happen if exiting an ephemeral shell, it's started happening
significantly more frequently, which prompted a desire to fix it.
  • Loading branch information
Frontear committed Dec 10, 2024
1 parent caed403 commit e9b1839
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions modules/home-manager/programs/zsh/module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,17 @@ in {
(lib.mkIf (!osConfig.programs.zsh.enableCompletion) "The home-manager module will not handle completions, please enable programs.zsh.enableCompletions in your NixOS configuration if this is undesirable.")
];

# Persist the history file
my.persist.files = [
cfg.history.file
# Persisting the file itself is not possible due to the way
# ZSH attempts to merge history files together -- by trying
# to copy $HISTFILE.new onto $HISTFILE.
#
# This doesn't work well on a bind mount, so as a avoidance
# we simply persist the entire directory the history file
# is part of. This isn't ideal if the user tries to place
# the file in an extremely open path (like ~/.history), but
# there isn't any better handling here.
my.persist.directories = [
(builtins.dirOf cfg.history.file)
];

programs.zsh = lib.mkMerge [
Expand Down

0 comments on commit e9b1839

Please sign in to comment.