-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add 'services.lieer', which generates systemd timer and service units to synchronize a Gmail account with lieer. Per-account configuration lives in 'accounts.email.accounts.<name>.lieer.sync'.
- Loading branch information
Showing
10 changed files
with
154 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ lib, ... }: | ||
|
||
with lib; | ||
|
||
{ | ||
options.lieer.sync = { | ||
enable = mkEnableOption "lieer synchronization service"; | ||
|
||
frequency = mkOption { | ||
type = types.str; | ||
default = "*:0/5"; | ||
description = '' | ||
How often to synchronize the account. | ||
</para><para> | ||
This value is passed to the systemd timer configuration as the | ||
onCalendar option. See | ||
<citerefentry> | ||
<refentrytitle>systemd.time</refentrytitle> | ||
<manvolnum>7</manvolnum> | ||
</citerefentry> | ||
for more information about the format. | ||
''; | ||
}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
{ config, lib, pkgs, ... }: | ||
|
||
with lib; | ||
|
||
let | ||
cfg = config.services.lieer; | ||
|
||
syncAccounts = filter (a: a.lieer.enable && a.lieer.sync.enable) | ||
(attrValues config.accounts.email.accounts); | ||
|
||
escapeUnitName = name: | ||
let | ||
good = upperChars ++ lowerChars ++ stringToCharacters "0123456789-_"; | ||
subst = c: if any (x: x == c) good then c else "-"; | ||
in 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 = "${pkgs.gmailieer}/bin/gmi sync"; | ||
WorkingDirectory = account.maildir.absPath; | ||
}; | ||
}; | ||
}; | ||
|
||
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 = [ maintainers.tadfisher ]; | ||
|
||
options = { | ||
services.lieer.enable = | ||
mkEnableOption "lieer Gmail synchronization service"; | ||
}; | ||
|
||
config = mkIf cfg.enable { | ||
programs.lieer.enable = true; | ||
systemd.user.services = listToAttrs (map serviceUnit syncAccounts); | ||
systemd.user.timers = listToAttrs (map timerUnit syncAccounts); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{ lieer-service = ./lieer-service.nix; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[Service] | ||
ExecStart=@lieer@/bin/gmi sync | ||
Type=oneshot | ||
WorkingDirectory=/home/hm-user/Mail/[email protected] | ||
|
||
[Unit] | ||
ConditionPathExists=/home/hm-user/Mail/[email protected]/.gmailieer.json | ||
Description=lieer Gmail synchronization for [email protected] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[Install] | ||
WantedBy=timers.target | ||
|
||
[Timer] | ||
OnCalendar=*:0/5 | ||
RandomizedDelaySec=30 | ||
|
||
[Unit] | ||
Description=lieer Gmail synchronization for [email protected] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{ config, lib, pkgs, ... }: | ||
|
||
with lib; | ||
|
||
{ | ||
imports = [ ../../accounts/email-test-accounts.nix ]; | ||
|
||
config = { | ||
home.username = "hm-user"; | ||
home.homeDirectory = "/home/hm-user"; | ||
|
||
services.lieer.enable = true; | ||
|
||
accounts.email.accounts = { | ||
"[email protected]".lieer.enable = true; | ||
"[email protected]".lieer.sync.enable = true; | ||
}; | ||
|
||
nixpkgs.overlays = [ | ||
(self: super: { | ||
gmailieer = super.gmailieer // { outPath = "@lieer@"; }; | ||
}) | ||
]; | ||
|
||
nmt.script = '' | ||
assertFileExists home-files/.config/systemd/user/lieer-hm-example-com.service | ||
assertFileExists home-files/.config/systemd/user/lieer-hm-example-com.timer | ||
assertFileContent home-files/.config/systemd/user/lieer-hm-example-com.service \ | ||
${./lieer-service-expected.service} | ||
assertFileContent home-files/.config/systemd/user/lieer-hm-example-com.timer \ | ||
${./lieer-service-expected.timer} | ||
''; | ||
}; | ||
} |