git: generate identities from mail accounts

This commit is contained in:
Matthieu Coudron 2019-01-21 17:14:22 +09:00 committed by Robert Helgesson
parent 604fc92943
commit a68c8cf5f1
No known key found for this signature in database
GPG key ID: 36BDAA14C2797E89

View file

@ -63,7 +63,10 @@ in
type = types.package; type = types.package;
default = pkgs.git; default = pkgs.git;
defaultText = "pkgs.git"; defaultText = "pkgs.git";
description = "Git package to install."; description = ''
Git package to install. Use <varname>pkgs.gitAndTools.gitFull</varname>
to gain access to <command>git send-email</command> for instance.
'';
}; };
userName = mkOption { userName = mkOption {
@ -142,6 +145,26 @@ in
}; };
} }
{
programs.git.iniContent =
let
hasSmtp = name: account: account.smtp != null;
genIdentity = name: account: with account;
nameValuePair "sendemail.${name}" ({
smtpEncryption = if smtp.tls.enable then "tls" else "";
smtpServer = smtp.host;
smtpUser = userName;
from = address;
}
// optionalAttrs (smtp.port != null) {
smtpServerPort = smtp.port;
});
in
mapAttrs' genIdentity
(filterAttrs hasSmtp config.accounts.email.accounts);
}
(mkIf (cfg.signing != null) { (mkIf (cfg.signing != null) {
programs.git.iniContent = { programs.git.iniContent = {
user.signingKey = cfg.signing.key; user.signingKey = cfg.signing.key;