add email stubs

This commit is contained in:
Ray Andrew 2025-03-04 00:04:25 -06:00
parent 7685baaa99
commit 5fdb6b7d2f
No known key found for this signature in database
6 changed files with 167 additions and 20 deletions

View file

@ -7,6 +7,7 @@
... ...
}: { }: {
imports = [ imports = [
./email
./ssh ./ssh
./git.nix ./git.nix
./gui.nix ./gui.nix

117
home/email/davmail.nix Normal file
View file

@ -0,0 +1,117 @@
{
config,
lib,
pkgs,
home-dir,
...
}:
let
cfg = config.services.davmail;
configType =
with lib.types;
oneOf [
(attrsOf configType)
str
int
bool
]
// {
description = "davmail config type (str, int, bool or attribute set thereof)";
};
toStr = val: if lib.isBool val then lib.boolToString val else toString val;
linesForAttrs =
attrs:
lib.concatMap (
name:
let
value = attrs.${name};
in
if lib.isAttrs value then
map (line: name + "." + line) (linesForAttrs value)
else
[ "${name}=${toStr value}" ]
) (lib.attrNames attrs);
configFile = pkgs.writeText "davmail.properties" (
lib.concatStringsSep "\n" (linesForAttrs cfg.config)
);
in
{
options.services.davmail = {
enable = lib.mkEnableOption "davmail, an MS Exchange gateway";
url = lib.mkOption {
type = lib.types.str;
description = "Outlook Web Access URL to access the exchange server, i.e. the base webmail URL.";
example = "https://outlook.office365.com/EWS/Exchange.asmx";
};
config = lib.mkOption {
type = configType;
default = { };
description = ''
Davmail configuration. Refer to
<http://davmail.sourceforge.net/serversetup.html>
and <http://davmail.sourceforge.net/advanced.html>
for details on supported values.
'';
example = lib.literalExpression ''
{
davmail.allowRemote = true;
davmail.imapPort = 55555;
davmail.bindAddress = "10.0.1.2";
davmail.smtpSaveInSent = true;
davmail.folderSizeLimit = 10;
davmail.caldavAutoSchedule = false;
log4j.logger.rootLogger = "DEBUG";
}
'';
};
};
config = lib.mkIf cfg.enable {
services.davmail.config = {
davmail = lib.mapAttrs (name: lib.mkDefault) {
server = true;
disableUpdateCheck = true;
logFilePath = "/tmp/davmail.log";
logFileSize = "1MB";
mode = "auto";
url = cfg.url;
caldavPort = 1080;
imapPort = 1143;
ldapPort = 1389;
popPort = 1110;
smtpPort = 1025;
oauth.tokenFilePath = "${home-dir}/.config/davmail/token";
};
log4j = {
logger.davmail = lib.mkDefault "WARN";
logger.httpclient.wire = lib.mkDefault "WARN";
logger.org.apache.commons.httpclient = lib.mkDefault "WARN";
rootLogger = lib.mkDefault "WARN";
};
};
systemd.user.services.davmail = {
Unit = {
Description = "DavMail POP/IMAP/SMTP Exchange Gateway";
};
Install = {
WantedBy = [ "default.target" ];
};
Service = {
Type = "simple";
ExecStart = "${pkgs.davmail}/bin/davmail ${configFile}";
Restart = "on-failure";
};
};
home.packages = [ pkgs.davmail ];
};
}

31
home/email/default.nix Normal file
View file

@ -0,0 +1,31 @@
{
pkgs,
lib,
config,
user,
home-dir,
...
}:
{
imports = [
./davmail.nix
];
options.custom.email = with lib; {
enable = mkEnableOption "Enable email";
davmail = mkEnableOption "Enable DavMail";
};
config = lib.mkIf config.custom.email.enable {
services.davmail = {
enable = config.custom.email.davmail;
url = "https://outlook.office365.com/EWS/Exchange.asmx";
config = {
davmail.mode = "O365Manual";
davmail.keepDelay = 30;
# log4j.logger.davmail = "DEBUG";
};
};
};
}

View file

@ -30,24 +30,24 @@ let
./${host} ./${host}
./${host}/hardware.nix ./${host}/hardware.nix
../nixos ../nixos
{ ({config, ...}: {
home-manager = { home-manager = {
useGlobalPkgs = true; useGlobalPkgs = true;
useUserPackages = true; useUserPackages = true;
extraSpecialArgs = specialArgs // { extraSpecialArgs = specialArgs // {
inherit host user system dots; inherit host user system dots;
home-dir = config.home-manager.users.${user}.home.homeDirectory;
}; };
users.${user} = { users.${user} = {
imports = [ imports = [
inputs.nix-index-database.hmModules.nix-index inputs.nix-index-database.hmModules.nix-index
./${host}/home.nix
../home ../home
]; ] ++ lib.optional(builtins.pathExists ./${host}/home.nix) ./${host}/home.nix;
}; };
}; };
} })
# alias for home-manager # alias for home-manager
(lib.mkAliasOptionModule [ "hm" ] [ (lib.mkAliasOptionModule [ "hm" ] [
"home-manager" "home-manager"

View file

@ -39,4 +39,18 @@
extraGroups = ["wheel" "video" "audio" "networkmanager"]; extraGroups = ["wheel" "video" "audio" "networkmanager"];
}; };
}; };
# home manager
hm.custom = {
latex.enable = true;
gui = {
default.enable = true;
i3.enable = true;
ghostty.enable = true;
};
email = {
enable = true;
davmail = true;
};
};
} }

View file

@ -1,16 +0,0 @@
{
config,
lib,
pkgs,
...
}:
{
custom = {
latex.enable = true;
gui = {
default.enable = true;
i3.enable = true;
ghostty.enable = true;
};
};
}