mirror of
https://github.com/nix-community/home-manager
synced 2024-11-26 21:19:45 +01:00
mu: run initialization command when personal addresses change
When the user changes which addresses mu should consider 'personal', mu's store should be reinitialized. After this change, the activation script parses the previously configured list of addresses and compares it with the new one. If they differ, it runs the init command even when the store has already been initialized.
This commit is contained in:
parent
f3a2ff6958
commit
fd326d8cfe
2 changed files with 22 additions and 12 deletions
|
@ -9,17 +9,22 @@ let
|
||||||
# Used to generate command line arguments that mu can operate with.
|
# Used to generate command line arguments that mu can operate with.
|
||||||
genCmdMaildir = path: "--maildir=" + path;
|
genCmdMaildir = path: "--maildir=" + path;
|
||||||
|
|
||||||
# Takes the list of accounts with mu.enable = true, and generates a
|
# Sorted list of personal email addresses to register
|
||||||
# command-line flag for initializing the mu database.
|
sortedAddresses = let
|
||||||
myAddresses = let
|
|
||||||
# Set of email account sets where mu.enable = true.
|
# Set of email account sets where mu.enable = true.
|
||||||
muAccounts =
|
muAccounts =
|
||||||
filter (a: a.mu.enable) (attrValues config.accounts.email.accounts);
|
filter (a: a.mu.enable) (attrValues config.accounts.email.accounts);
|
||||||
addrs = map (a: a.address) muAccounts;
|
addrs = map (a: a.address) muAccounts;
|
||||||
# Construct list of lists containing email aliases, and flatten
|
# Construct list of lists containing email aliases, and flatten
|
||||||
aliases = flatten (map (a: a.aliases) muAccounts);
|
aliases = flatten (map (a: a.aliases) muAccounts);
|
||||||
# Prefix --my-address= to each account's address AND all defined aliases
|
# Sort the list
|
||||||
addMyAddress = map (addr: "--my-address=" + addr) (addrs ++ aliases);
|
in sort lessThan (addrs ++ aliases);
|
||||||
|
|
||||||
|
# Takes the list of accounts with mu.enable = true, and generates a
|
||||||
|
# command-line flag for initializing the mu database.
|
||||||
|
myAddresses = let
|
||||||
|
# Prefix --my-address= to each account's address and all defined aliases
|
||||||
|
addMyAddress = map (addr: "--my-address=" + addr) sortedAddresses;
|
||||||
in concatStringsSep " " addMyAddress;
|
in concatStringsSep " " addMyAddress;
|
||||||
|
|
||||||
in {
|
in {
|
||||||
|
@ -49,14 +54,19 @@ in {
|
||||||
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 = config.xdg.cacheHome + "/mu";
|
||||||
|
muExe = getExe cfg.package;
|
||||||
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 and registered personal addresses remain the same,
|
||||||
|
# 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
|
||||||
# only created during the initial index.
|
# only created during the initial index.
|
||||||
if [[ ! -d "${dbLocation}" ]]; then
|
MU_SORTED_ADDRS=$(run ${muExe} info store | ${
|
||||||
run ${
|
getExe pkgs.gawk
|
||||||
getExe cfg.package
|
} '/personal-address/{print $4}' | LC_ALL=C sort | paste -sd ' ')
|
||||||
} init ${maildirOption} ${myAddresses} $VERBOSE_ARG;
|
if [[ ! -d "${dbLocation}" || ! "$MU_SORTED_ADDRS" = "${
|
||||||
|
concatStringsSep " " sortedAddresses
|
||||||
|
}" ]]; then
|
||||||
|
run ${muExe} init ${maildirOption} ${myAddresses} $VERBOSE_ARG;
|
||||||
fi
|
fi
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
|
@ -16,9 +16,9 @@
|
||||||
|
|
||||||
nmt.script = ''
|
nmt.script = ''
|
||||||
assertFileContains activate \
|
assertFileContains activate \
|
||||||
'if [[ ! -d "/home/hm-user/.cache/mu" ]]; then'
|
'if [[ ! -d "/home/hm-user/.cache/mu" || ! "$MU_SORTED_ADDRS" = "foo@example.com hm@example.com" ]]; then'
|
||||||
|
|
||||||
assertFileContains activate \
|
assertFileContains activate \
|
||||||
'run @mu@/bin/mu init --maildir=/home/hm-user/Mail --my-address=hm@example.com --my-address=foo@example.com $VERBOSE_ARG;'
|
'run @mu@/bin/mu init --maildir=/home/hm-user/Mail --my-address=foo@example.com --my-address=hm@example.com $VERBOSE_ARG;'
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue