mirror of
https://github.com/nix-community/home-manager
synced 2024-11-23 11:39:46 +01:00
git: rely on msmtp for smtp if msmtp is enabled (#1829)
If a user using msmtp to send all their email, it would be preferred if git used it as well. The only settings necessary are to set the smtp server to the msmtp binary and set envelop sender to true, which makes git call msmtp with the -f flag to set the from address from the email.
This commit is contained in:
parent
3327cbe1f9
commit
aa479b0124
5 changed files with 88 additions and 14 deletions
|
@ -1863,6 +1863,15 @@ in
|
|||
lists to polybar-style 'foo-0, foo-1, ...' lists.
|
||||
'';
|
||||
}
|
||||
{
|
||||
time = "2021-02-25T22:36:43+00:00";
|
||||
condition = config.programs.git.enable
|
||||
&& any config.accounts.email.accounts (account: account.msmtp.enable);
|
||||
message = ''
|
||||
Git will now defer to msmtp for sending emails if
|
||||
'accounts.email.accounts.<name>.msmtp.enable' is true.
|
||||
'';
|
||||
}
|
||||
];
|
||||
};
|
||||
}
|
||||
|
|
|
@ -276,7 +276,12 @@ in {
|
|||
|
||||
genIdentity = name: account:
|
||||
with account;
|
||||
nameValuePair "sendemail.${name}" ({
|
||||
nameValuePair "sendemail.${name}" (if account.msmtp.enable then {
|
||||
smtpServer = "${pkgs.msmtp}/bin/msmtp";
|
||||
envelopeSender = true;
|
||||
from = address;
|
||||
} else
|
||||
{
|
||||
smtpEncryption = if smtp.tls.enable then
|
||||
(if smtp.tls.useStartTls
|
||||
|| versionOlder config.home.stateVersion "20.09" then
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
{
|
||||
git-with-email = ./git-with-email.nix;
|
||||
git-with-most-options = ./git.nix;
|
||||
git-with-msmtp = ./git-with-msmtp.nix;
|
||||
git-with-str-extra-config = ./git-with-str-extra-config.nix;
|
||||
}
|
||||
|
|
14
tests/modules/programs/git/git-with-msmtp-expected.conf
Normal file
14
tests/modules/programs/git/git-with-msmtp-expected.conf
Normal file
|
@ -0,0 +1,14 @@
|
|||
[sendemail "hm-account"]
|
||||
from = "hm@example.org"
|
||||
smtpEncryption = "tls"
|
||||
smtpServer = "smtp.example.org"
|
||||
smtpUser = "home.manager.jr"
|
||||
|
||||
[sendemail "hm@example.com"]
|
||||
envelopeSender = true
|
||||
from = "hm@example.com"
|
||||
smtpServer = "@msmtp@/bin/msmtp"
|
||||
|
||||
[user]
|
||||
email = "hm@example.com"
|
||||
name = "H. M. Test"
|
45
tests/modules/programs/git/git-with-msmtp.nix
Normal file
45
tests/modules/programs/git/git-with-msmtp.nix
Normal file
|
@ -0,0 +1,45 @@
|
|||
{ config, lib, pkgs, ... }:
|
||||
|
||||
with lib;
|
||||
|
||||
{
|
||||
imports = [ ../../accounts/email-test-accounts.nix ];
|
||||
|
||||
config = {
|
||||
accounts.email.accounts."hm@example.com".msmtp.enable = true;
|
||||
programs.git = {
|
||||
enable = true;
|
||||
package = pkgs.gitMinimal;
|
||||
userEmail = "hm@example.com";
|
||||
userName = "H. M. Test";
|
||||
};
|
||||
|
||||
home.stateVersion = "20.09";
|
||||
|
||||
nmt.script = ''
|
||||
function assertGitConfig() {
|
||||
local value
|
||||
value=$(${pkgs.gitMinimal}/bin/git config \
|
||||
--file $TESTED/home-files/.config/git/config \
|
||||
--get $1)
|
||||
if [[ $value != $2 ]]; then
|
||||
fail "Expected option '$1' to have value '$2' but it was '$value'"
|
||||
fi
|
||||
}
|
||||
|
||||
assertFileExists home-files/.config/git/config
|
||||
assertFileContent home-files/.config/git/config \
|
||||
${
|
||||
pkgs.substituteAll {
|
||||
inherit (pkgs) msmtp;
|
||||
src = ./git-with-msmtp-expected.conf;
|
||||
}
|
||||
}
|
||||
|
||||
assertGitConfig "sendemail.hm@example.com.from" "hm@example.com"
|
||||
assertGitConfig "sendemail.hm-account.from" "hm@example.org"
|
||||
assertGitConfig "sendemail.hm@example.com.smtpServer" "${pkgs.msmtp}/bin/msmtp"
|
||||
assertGitConfig "sendemail.hm@example.com.envelopeSender" "true"
|
||||
'';
|
||||
};
|
||||
}
|
Loading…
Reference in a new issue