1
0
mirror of https://github.com/nix-community/home-manager synced 2024-06-01 20:43:34 +02:00

notmuch: fix database creation when using hooks

When an hook is defined, a side effect was the creation of the
${notmuchIni.database.path}/.notmuch/ directory by home-manager. If
the Xapian database does not exist yet but this .notmuch directory
exists, Notmuch is confused and throws an error when `notmuch new` is
run (while this should create the database the first time).

This commit changes the hooks paths to $XDG_CONFIG_HOME where Notmuch
expects them (see notmuch-config(1)) instead of inside the maildir
database directory.

It also moves the configuration where Notmuch expects it, but the
$NOTMUCH_CONFIG environment variable is kept for backward
compatibility.
This commit is contained in:
Thibaut Marty 2022-02-05 17:45:12 +01:00 committed by Robert Helgesson
parent 85bbc6cc12
commit 6d9d9294d0
No known key found for this signature in database
GPG Key ID: 36BDAA14C2797E89
5 changed files with 22 additions and 21 deletions

View File

@ -42,7 +42,8 @@ let
template = fromJSON (readFile ./astroid-config-template.json);
astroidConfig = foldl' recursiveUpdate template [
{
astroid.notmuch_config = "${config.xdg.configHome}/notmuch/notmuchrc";
astroid.notmuch_config =
"${config.xdg.configHome}/notmuch/default/config";
accounts = mapAttrs (n: accountAttr) astroidAccounts;
crypto.gpg.path = "${pkgs.gnupg}/bin/gpg";
}

View File

@ -167,29 +167,29 @@ in {
home.packages = [ pkgs.notmuch ];
home.sessionVariables = {
NOTMUCH_CONFIG = "${config.xdg.configHome}/notmuch/notmuchrc";
NOTMUCH_CONFIG = "${config.xdg.configHome}/notmuch/default/config";
NMBGIT = "${config.xdg.dataHome}/notmuch/nmbug";
};
xdg.configFile."notmuch/notmuchrc".text =
let toIni = generators.toINI { mkKeyValue = mkIniKeyValue; };
in ''
# Generated by Home Manager.
'' + toIni notmuchIni;
home.file = let
xdg.configFile = let
hook = name: cmds: {
"${notmuchIni.database.path}/.notmuch/hooks/${name}".source =
pkgs.writeShellScript name ''
export PATH="${pkgs.notmuch}/bin''${PATH:+:}$PATH"
export NOTMUCH_CONFIG="${config.xdg.configHome}/notmuch/notmuchrc"
export NMBGIT="${config.xdg.dataHome}/notmuch/nmbug"
"notmuch/default/hooks/${name}".source = pkgs.writeShellScript name ''
export PATH="${pkgs.notmuch}/bin''${PATH:+:}$PATH"
export NOTMUCH_CONFIG="${config.xdg.configHome}/notmuch/default/config"
export NMBGIT="${config.xdg.dataHome}/notmuch/nmbug"
${cmds}
'';
${cmds}
'';
};
in optionalAttrs (cfg.hooks.preNew != "") (hook "pre-new" cfg.hooks.preNew)
in {
"notmuch/default/config".text =
let toIni = generators.toINI { mkKeyValue = mkIniKeyValue; };
in ''
# Generated by Home Manager.
'' + toIni notmuchIni;
}
// optionalAttrs (cfg.hooks.preNew != "") (hook "pre-new" cfg.hooks.preNew)
// optionalAttrs (cfg.hooks.postNew != "")
(hook "post-new" cfg.hooks.postNew)
// optionalAttrs (cfg.hooks.postInsert != "")

View File

@ -27,7 +27,7 @@ let
Type = "simple";
} // optionalAttrs account.notmuch.enable {
Environment =
"NOTMUCH_CONFIG=${config.xdg.configHome}/notmuch/notmuchrc";
"NOTMUCH_CONFIG=${config.xdg.configHome}/notmuch/default/config";
};
Install = { WantedBy = [ "default.target" ]; };

View File

@ -27,7 +27,7 @@ let
ExecStart = "${config.programs.lieer.package}/bin/gmi sync";
WorkingDirectory = account.maildir.absPath;
Environment =
"NOTMUCH_CONFIG=${config.xdg.configHome}/notmuch/notmuchrc";
"NOTMUCH_CONFIG=${config.xdg.configHome}/notmuch/default/config";
};
};
};

View File

@ -1,5 +1,5 @@
[Service]
Environment=NOTMUCH_CONFIG=/home/hm-user/.config/notmuch/notmuchrc
Environment=NOTMUCH_CONFIG=/home/hm-user/.config/notmuch/default/config
ExecStart=@gmailieer@/bin/gmi sync
Type=oneshot
WorkingDirectory=/home/hm-user/Mail/hm@example.com