mu: add support for setting muhome

The database path can be set by the user, this is useful for keeping
the Maildir and the Mu Xapian cache together without affecting
XDG_CACHE_HOME

Fixes #5534.

Signed-off-by: J. Dekker <jdek@itanimul.li>
This commit is contained in:
J. Dekker 2024-06-14 00:49:32 +02:00
parent 8d5e27b480
commit 7f13edb3b8

View file

@ -31,6 +31,15 @@ in {
package = mkPackageOption pkgs "mu" { }; package = mkPackageOption pkgs "mu" { };
home = mkOption {
type = with types; nullOr str;
default = null;
example = "\${config.home.homeDirectory}/Maildir/.mu";
description = ''
Directory to store Mu's database.
'';
};
# No options/config file present for mu, and program author will not be # No options/config file present for mu, and program author will not be
# adding one soon. See https://github.com/djcb/mu/issues/882 for more # adding one soon. See https://github.com/djcb/mu/issues/882 for more
# information about this. # information about this.
@ -46,9 +55,13 @@ in {
config = mkIf cfg.enable { config = mkIf cfg.enable {
home.packages = [ cfg.package ]; home.packages = [ cfg.package ];
home.sessionVariables = filterAttrs (n: v: v != null) {
MUHOME = cfg.home;
};
home.activation.runMuInit = let home.activation.runMuInit = let
maildirOption = genCmdMaildir config.accounts.email.maildirBasePath; maildirOption = genCmdMaildir config.accounts.email.maildirBasePath;
dbLocation = config.xdg.cacheHome + "/mu"; dbLocation = if cfg.home != null then cfg.home else (config.xdg.cacheHome + "/mu");
in hm.dag.entryAfter [ "writeBoundary" ] '' in hm.dag.entryAfter [ "writeBoundary" ] ''
# If the database directory exists, then `mu init` should NOT be run. # If the database directory exists, then `mu init` should NOT be run.
# In theory, mu is the only thing that creates that directory, and it is # In theory, mu is the only thing that creates that directory, and it is
@ -56,7 +69,7 @@ in {
if [[ ! -d "${dbLocation}" ]]; then if [[ ! -d "${dbLocation}" ]]; then
run ${ run ${
getExe cfg.package getExe cfg.package
} init ${maildirOption} ${myAddresses} $VERBOSE_ARG; } init ${maildirOption} --muhome "${dbLocation}" ${myAddresses} $VERBOSE_ARG;
fi fi
''; '';
}; };