mirror of
https://github.com/nix-community/home-manager
synced 2025-02-02 06:15:03 +01:00
mu: allow option to set muhome
Allows for the database path for mu to be configured. Useful for keeping the maildir and mu xapian cache together without having to modify XDG_CACHE_HOME. Add test to check for custom home setting. Fixes #5534
This commit is contained in:
parent
0b8df9eeb6
commit
bb14224f51
4 changed files with 46 additions and 5 deletions
|
@ -36,6 +36,16 @@ in {
|
|||
|
||||
package = mkPackageOption pkgs "mu" { };
|
||||
|
||||
home = mkOption {
|
||||
type = types.path;
|
||||
default = config.xdg.cacheHome + "/mu";
|
||||
defaultText = literalExpression ''config.xdg.cacheHome + "/mu"'';
|
||||
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
|
||||
# adding one soon. See https://github.com/djcb/mu/issues/882 for more
|
||||
# information about this.
|
||||
|
@ -51,9 +61,10 @@ in {
|
|||
config = mkIf cfg.enable {
|
||||
home.packages = [ cfg.package ];
|
||||
|
||||
home.sessionVariables.MUHOME = cfg.home;
|
||||
|
||||
home.activation.runMuInit = let
|
||||
maildirOption = genCmdMaildir config.accounts.email.maildirBasePath;
|
||||
dbLocation = config.xdg.cacheHome + "/mu";
|
||||
muExe = getExe cfg.package;
|
||||
gawkExe = getExe pkgs.gawk;
|
||||
in hm.dag.entryAfter [ "writeBoundary" ] ''
|
||||
|
@ -62,10 +73,12 @@ in {
|
|||
# In theory, mu is the only thing that creates that directory, and it is
|
||||
# only created during the initial index.
|
||||
MU_SORTED_ADDRS=$((${muExe} info store | ${gawkExe} '/personal-address/{print $4}' | LC_ALL=C sort | paste -sd ' ') || exit 0)
|
||||
if [[ ! -d "${dbLocation}" || ! "$MU_SORTED_ADDRS" = "${
|
||||
if [[ ! -d "${cfg.home}" || ! "$MU_SORTED_ADDRS" = "${
|
||||
concatStringsSep " " sortedAddresses
|
||||
}" ]]; then
|
||||
run ${muExe} init ${maildirOption} ${myAddresses} $VERBOSE_ARG;
|
||||
run ${muExe} init ${maildirOption} --muhome "${
|
||||
escapeShellArg cfg.home
|
||||
}" ${myAddresses} $VERBOSE_ARG;
|
||||
fi
|
||||
'';
|
||||
};
|
||||
|
|
|
@ -19,6 +19,6 @@
|
|||
'if [[ ! -d "/home/hm-user/.cache/mu" || ! "$MU_SORTED_ADDRS" = "foo@example.com hm@example.com" ]]; then'
|
||||
|
||||
assertFileContains activate \
|
||||
'run @mu@/bin/mu init --maildir=/home/hm-user/Mail --my-address=foo@example.com --my-address=hm@example.com $VERBOSE_ARG;'
|
||||
'run @mu@/bin/mu init --maildir=/home/hm-user/Mail --muhome "/home/hm-user/.cache/mu" --my-address=foo@example.com --my-address=hm@example.com $VERBOSE_ARG;'
|
||||
'';
|
||||
}
|
||||
|
|
25
tests/modules/programs/mu/custom-configuration.nix
Normal file
25
tests/modules/programs/mu/custom-configuration.nix
Normal file
|
@ -0,0 +1,25 @@
|
|||
{ config, ... }: {
|
||||
imports = [ ../../accounts/email-test-accounts.nix ];
|
||||
|
||||
accounts.email.accounts = {
|
||||
"hm@example.com" = {
|
||||
mu.enable = true;
|
||||
aliases = [ "foo@example.com" ];
|
||||
};
|
||||
};
|
||||
|
||||
programs.mu = {
|
||||
enable = true;
|
||||
home = config.xdg.dataHome + "/mu";
|
||||
};
|
||||
|
||||
test.stubs.mu = { name = "mu"; };
|
||||
|
||||
nmt.script = ''
|
||||
assertFileContains activate \
|
||||
'if [[ ! -d "/home/hm-user/.local/share/mu" || ! "$MU_SORTED_ADDRS" = "foo@example.com hm@example.com" ]]; then'
|
||||
|
||||
assertFileContains activate \
|
||||
'run @mu@/bin/mu init --maildir=/home/hm-user/Mail --muhome "/home/hm-user/.local/share/mu" --my-address=foo@example.com --my-address=hm@example.com $VERBOSE_ARG;'
|
||||
'';
|
||||
}
|
|
@ -1 +1,4 @@
|
|||
{ mu-basic-configuration = ./basic-configuration.nix; }
|
||||
{
|
||||
mu-basic-configuration = ./basic-configuration.nix;
|
||||
mu-custom-configuration = ./custom-configuration.nix;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue