Home-manager notmuch couldn't stat Maildir/.notmuch/xapian

I’ve setup notmuch with pre-new hook, and attempting to do notmuch new
I get an error:

Cannot open Xapian database at /home/efim/Maildir/.notmuch/xapian: Couldn't stat '/home/efim/Maildir/.notmuch/xapian'

For the longest while couldn’t find anything at all about that problem, in the end found few messages in nixos discourse:

"home-manager creates $MAILDIR/.notmuch/hooks directory. notmuch new looks if $MAILDIR/.notmuch exists, and if yes, assumes there’s a xapian DB or it fails. Manually deleting the whole .notmuch dir fixed the problem, but now there’s no hooks after rebuilding nixos "

So workaroud would be:

  • delete .notmuch directory
  • init xapian db by running notmuch new
  • modify hooks in nix configuration so that they would reapply on next nixos-rebuild switch