Use home-manager account data structures

This commit is contained in:
Simon Bruder 2022-06-16 21:19:04 +02:00
parent 0d125352a3
commit 6d061fa210
Signed by: simon
GPG key ID: 8D3C82F9F309F8EC
3 changed files with 333 additions and 263 deletions

View file

@ -0,0 +1,74 @@
{ config, ... }:
let
signaturePersonal = ''
--
Simon Bruder
Wallmersbach 42
97215 Uffenheim
🔑 (GPG): 47E7 559E 037A 3565 2DBB F8AA 8D3C 82F9 F309 F8EC
📧 (e-mail): simon@sbruder.de
📱 (mobile): +49 152 56561414
'';
in
{
accounts.email = {
accounts = {
personal = rec {
primary = true;
realName = "Simon Bruder";
address = "simon@sbruder.de";
aliases = [ ]; # FIXME!?
userName = address;
passwordCommand = "pass sbruder.de/mail";
imap = {
host = "vueko.sbruder.de";
tls.useStartTls = true;
};
smtp = {
host = "vueko.sbruder.de";
tls.useStartTls = true;
};
gpg = {
key = config.programs.gpg.settings.default-key;
signByDefault = true;
encryptByDefault = true;
};
signature.text = signaturePersonal;
aerc.enable = true;
};
riseup = rec {
realName = "Simon Bruder";
address = "sbruder@riseup.net";
userName = address;
passwordCommand = "pass web/riseup.net | head -n 1";
imap = {
host = "mail.riseup.net";
tls.useStartTls = true;
};
smtp = {
host = "mail.riseup.net";
tls.useStartTls = true;
};
gpg = {
key = config.programs.gpg.settings.default-key;
signByDefault = true;
encryptByDefault = true;
};
signature.text = signaturePersonal;
aerc.enable = true;
};
};
};
}

View file

@ -1,48 +1,42 @@
{ lib, pkgs, ... }:
{ config, lib, pkgs, ... }:
let
package = pkgs.aerc;
accountDefaults = {
smtp-starttls = "yes";
copy-to = "Sent";
signature-file = pkgs.writeText "signature" ''
--
Simon Bruder
Wallmersbach 42
97215 Uffenheim
🔑 (GPG): 47E7 559E 037A 3565 2DBB F8AA 8D3C 82F9 F309 F8EC
📧 (E-Mail): simon@sbruder.de
📱 (mobile): +49 152 56561414
'';
pgp-auto-sign = true;
pgp-key-id = "47E7559E037A35652DBBF8AA8D3C82F9F309F8EC";
pgp-opportunistic-encrypt = true;
};
in
{
options = {
accounts.email.accounts = lib.mkOption {
type = lib.types.attrsOf (lib.types.submodule {
options.aerc.enable = lib.mkEnableOption "aerc";
});
};
};
config = {
home.packages = [
package
];
xdg.configFile = {
"aerc/accounts.conf".text = lib.generators.toINI { } {
Personal = accountDefaults // {
source = "`imap://simon%40sbruder.de@vueko.sbruder.de`";
source-cred-cmd = "`pass sbruder.de/mail`";
outgoing = "`smtp+plain://simon%40sbruder.de@vueko.sbruder.de`";
outgoing-cred-cmd = "`pass sbruder.de/mail`";
from = "Simon Bruder <simon@sbruder.de>";
};
Riseup = accountDefaults // {
source = "`imap://sbruder@mail.riseup.net`";
source-cred-cmd = "`pass web/riseup.net | head -n 1`";
outgoing = "`smtp+plain://sbruder@mail.riseup.net`";
outgoing-cred-cmd = "`pass web/riseup.net | head -n 1`";
from = "Simon Bruder <sbruder@riseup.net>";
};
};
"aerc/accounts.conf".text = lib.generators.toINI { } (lib.mapAttrs
# incomplete support for all configuration options!
(name: config: with config; let
quoteMailAddress = lib.replaceChars [ "@" ] [ "%40" ];
in
{
source = "`imap://${quoteMailAddress address}@${imap.host}`";
source-cred-cmd = "`${lib.concatStringsSep " " passwordCommand}`";
outgoing = "`smtp+plain://${quoteMailAddress address}@${smtp.host}`";
outgoing-cred-cmd = "`${lib.concatStringsSep " " passwordCommand}`";
from = "${realName} <${address}>";
smtp-starttls = if smtp.tls.useStartTls then "yes" else "no";
copy-to = "Sent";
signature-file = pkgs.writeText "signature-${name}" signature.text;
pgp-key-id = gpg.key;
pgp-auto-sign = gpg.signByDefault;
pgp-opportunistic-encrypt = gpg.encryptByDefault;
})
(lib.filterAttrs
(_: config: config.aerc.enable)
config.accounts.email.accounts));
"aerc/aerc.conf".text = lib.generators.toINI { } {
general = {
@ -275,4 +269,5 @@ in
"completion_default.bg" = 0;
});
};
};
}

View file

@ -1,5 +1,6 @@
{
imports = [
./accounts.nix
./aerc
];
}