1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2025-12-01 06:31:04 +01:00
home-manager/modules/services/lieer.nix
Austin Horstman 86402a17b6 treewide: flatten single file modules
Some files don't need nesting and can be root level again to reduce
conflicts with other PRs.

Signed-off-by: Austin Horstman <khaneliman12@gmail.com>
2025-06-23 16:20:26 -05:00

72 lines
1.8 KiB
Nix

{
config,
lib,
pkgs,
...
}:
let
cfg = config.services.lieer;
syncAccounts = lib.filter (a: a.lieer.enable && a.lieer.sync.enable) (
lib.attrValues config.accounts.email.accounts
);
escapeUnitName =
name:
let
good = lib.upperChars ++ lib.lowerChars ++ lib.stringToCharacters "0123456789-_";
subst = c: if lib.any (x: x == c) good then c else "-";
in
lib.stringAsChars subst name;
serviceUnit = account: {
name = escapeUnitName "lieer-${account.name}";
value = {
Unit = {
Description = "lieer Gmail synchronization for ${account.name}";
ConditionPathExists = "${account.maildir.absPath}/.gmailieer.json";
};
Service = {
Type = "oneshot";
ExecStart = "${config.programs.lieer.package}/bin/gmi sync";
WorkingDirectory = account.maildir.absPath;
Environment = "NOTMUCH_CONFIG=${config.xdg.configHome}/notmuch/default/config";
};
};
};
timerUnit = account: {
name = escapeUnitName "lieer-${account.name}";
value = {
Unit = {
Description = "lieer Gmail synchronization for ${account.name}";
};
Timer = {
OnCalendar = account.lieer.sync.frequency;
RandomizedDelaySec = 30;
};
Install = {
WantedBy = [ "timers.target" ];
};
};
};
in
{
meta.maintainers = [ lib.maintainers.tadfisher ];
options.services.lieer.enable = lib.mkEnableOption "lieer Gmail synchronization service";
config = lib.mkIf cfg.enable {
assertions = [
(lib.hm.assertions.assertPlatform "services.lieer" pkgs lib.platforms.linux)
];
programs.lieer.enable = true;
systemd.user.services = lib.listToAttrs (map serviceUnit syncAccounts);
systemd.user.timers = lib.listToAttrs (map timerUnit syncAccounts);
};
}