Skip to content

Commit

Permalink
mu: allow option to set muhome
Browse files Browse the repository at this point in the history
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 nix-community#5534
  • Loading branch information
NovaViper authored Jan 21, 2025
1 parent 0b8df9e commit bb14224
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 5 deletions.
19 changes: 16 additions & 3 deletions modules/programs/mu.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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" ] ''
Expand All @@ -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
'';
};
Expand Down
2 changes: 1 addition & 1 deletion tests/modules/programs/mu/basic-configuration.nix
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@
'if [[ ! -d "/home/hm-user/.cache/mu" || ! "$MU_SORTED_ADDRS" = "[email protected] [email protected]" ]]; then'
assertFileContains activate \
'run @mu@/bin/mu init --maildir=/home/hm-user/Mail [email protected] [email protected] $VERBOSE_ARG;'
'run @mu@/bin/mu init --maildir=/home/hm-user/Mail --muhome "/home/hm-user/.cache/mu" --[email protected] [email protected] $VERBOSE_ARG;'
'';
}
25 changes: 25 additions & 0 deletions tests/modules/programs/mu/custom-configuration.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{ config, ... }: {
imports = [ ../../accounts/email-test-accounts.nix ];

accounts.email.accounts = {
"[email protected]" = {
mu.enable = true;
aliases = [ "[email protected]" ];
};
};

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" = "[email protected] [email protected]" ]]; then'
assertFileContains activate \
'run @mu@/bin/mu init --maildir=/home/hm-user/Mail --muhome "/home/hm-user/.local/share/mu" [email protected] [email protected] $VERBOSE_ARG;'
'';
}
5 changes: 4 additions & 1 deletion tests/modules/programs/mu/default.nix
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
{ mu-basic-configuration = ./basic-configuration.nix; }
{
mu-basic-configuration = ./basic-configuration.nix;
mu-custom-configuration = ./custom-configuration.nix;
}

0 comments on commit bb14224

Please sign in to comment.