🚀 add custom email module

dev-docs
Moritz Böhme 2022-03-23 12:33:15 +01:00
parent 9c7be9b751
commit 0400e3f7bd
No known key found for this signature in database
GPG Key ID: 213820E2795F5CF5
3 changed files with 103 additions and 57 deletions

17
config/nixos-desktop.nix Normal file
View File

@ -0,0 +1,17 @@
{ config, lib, pkgs, ... }:
{
modules = {
gaming = true;
editors = {
idea = true;
code = true;
};
desktop.apps.email = {
enable = true;
passwordFile = ../secrets/email-desktop.age;
};
};
}

8
config/nixos-laptop.nix Normal file
View File

@ -0,0 +1,8 @@
{ config, lib, pkgs, ... }:
{
modules.desktop.apps.email = {
enable = true;
passwordFile = ../secrets/email-desktop.age;
};
}

View File

@ -1,77 +1,98 @@
{ config, lib, pkgs, ... }: { config, lib, pkgs, ... }:
with lib;
let let
cfg = config.modules.desktop.apps.email;
name = "Moritz Böhme"; name = "Moritz Böhme";
email = "mail@moritzboeh.me"; email = "mail@moritzboeh.me";
mailDirectory = "/home/moritz/.mail"; mailDirectory = "/home/moritz/.mail";
in { in {
environment.systemPackages = with pkgs; [ protonmail-bridge ]; options.modules.desktop.apps.email = {
systemd.user.services.protonmail-bridge = { enable = mkEnableOption "email module";
description = "Protonmail Bridge"; passwordFile = mkOption {
enable = true; default = null;
script = type = types.path;
"${pkgs.protonmail-bridge}/bin/protonmail-bridge --log-level debug"; description = "File containing the email password.";
path = [ };
pkgs.gnome3.gnome-keyring
]; # HACK: https://github.com/ProtonMail/proton-bridge/issues/176
wantedBy = [ "graphical-session.target" ];
partOf = [ "graphical-session.target" ];
}; };
home-manager.users.moritz = {
home = { packages = with pkgs; [ thunderbird ]; }; config = mkIf cfg.enable {
programs = { # Protonbridge Setup
msmtp.enable = true; environment.systemPackages = with pkgs; [ protonmail-bridge ];
mbsync.enable = true; systemd.user.services.protonmail-bridge = {
description = "Protonmail Bridge";
enable = true;
script =
"${pkgs.protonmail-bridge}/bin/protonmail-bridge --log-level debug";
path = [
pkgs.gnome3.gnome-keyring
]; # HACK: https://github.com/ProtonMail/proton-bridge/issues/176
wantedBy = [ "graphical-session.target" ];
partOf = [ "graphical-session.target" ];
};
age.secrets.email = {
file = cfg.passwordFile;
owner = "1000";
}; };
services = { # Email Applications
mbsync = { home-manager.users.moritz = {
enable = true; home = { packages = with pkgs; [ thunderbird ]; };
frequency = "*:0/15"; programs = {
preExec = "${pkgs.isync}/bin/mbsync -Ha"; msmtp.enable = true;
postExec = "${pkgs.mu}/bin/mu index -m ${mailDirectory}"; mbsync.enable = true;
}; };
};
accounts.email = { services = {
maildirBasePath = mailDirectory; mbsync = {
accounts = { enable = true;
default = { frequency = "*:0/15";
address = email; preExec = "${pkgs.isync}/bin/mbsync -Ha";
userName = email; postExec = "${pkgs.mu}/bin/mu index -m ${mailDirectory}";
flavor = "plain"; };
primary = true; };
passwordCommand = "${pkgs.coreutils}/bin/cat /run/agenix/email";
mbsync = { accounts.email = {
enable = true; maildirBasePath = mailDirectory;
create = "both"; accounts = {
expunge = "both"; default = {
patterns = [ "*" ]; address = email;
}; userName = email;
realName = name; flavor = "plain";
msmtp.enable = true; primary = true;
imap = { passwordCommand = "${pkgs.coreutils}/bin/cat /run/agenix/email";
host = "127.0.0.1"; mbsync = {
port = 1143;
tls = {
enable = true; enable = true;
useStartTls = true; create = "both";
certificatesFile = expunge = "both";
"/home/moritz/.config/protonmail/bridge/cert.pem"; patterns = [ "*" ];
}; };
}; realName = name;
smtp = { msmtp.enable = true;
host = "127.0.0.1"; imap = {
port = 1025; host = "127.0.0.1";
tls = { port = 1143;
enable = true; tls = {
useStartTls = true; enable = true;
certificatesFile = useStartTls = true;
"/home/moritz/.config/protonmail/bridge/cert.pem"; certificatesFile =
"/home/moritz/.config/protonmail/bridge/cert.pem";
};
};
smtp = {
host = "127.0.0.1";
port = 1025;
tls = {
enable = true;
useStartTls = true;
certificatesFile =
"/home/moritz/.config/protonmail/bridge/cert.pem";
};
}; };
}; };
}; };
}; };
}; };
networking.firewall.allowedTCPPorts = [ 33728 1025 1143 ];
}; };
networking.firewall.allowedTCPPorts = [ 33728 1025 1143 ];
} }