# unpackPhase
# patchPhase
# configurePhase
# buildPhase
# checkPhase
# installPhase
# fixupPhase
# installCheckPhase
# distPhase
{
  stdenv,
  pkgs,
  sqlite,
  ...
}:
stdenv.mkDerivation {
  name = "zsh-histdb";
  src = pkgs.fetchgit {
    url = "https://github.com/larkery/zsh-histdb.git";
    rev = "90a6c104d0fcc0410d665e148fa7da28c49684eb";
    sha256 = "sha256-vtG1poaRVbfb/wKPChk1WpPgDq+7udLqLfYfLqap4Vg=";
  };
  buildInputs = [ sqlite ];
  phases = [
    "installPhase"
  ];
  installPhase = ''
    runHook preInstall
    mkdir -p $out/share/zsh/plugins/zsh-histdb
    cp -r $src/histdb-* $src/*.zsh $src/db_migrations $out/share/zsh/plugins/zsh-histdb/
    runHook postInstall
  '';
  postInstall = ''
    substituteInPlace $out/share/zsh/plugins/zsh-histdb/sqlite-history.zsh $out/share/zsh/plugins/zsh-histdb/histdb-merge $out/share/zsh/plugins/zsh-histdb/histdb-migrate --replace-fail "sqlite3" "${sqlite}/bin/sqlite3"
  '';
}
