fork/home-manager
git clone https://git.julia.blue/fork/home-manager
6d9d9294
master
1{ config , lib , pkgs , ...} : 2 3with lib ; 4 5let 6cfg = config . services . lieer ; 7 8syncAccounts = filter ( a :a . lieer . enable && a . lieer . sync . enable ) 9( attrValues config . accounts . . accounts ); 10 11escapeUnitName = name : 12let 13good = upperChars ++ lowerChars ++ stringToCharacters "0123456789-_" ; 14subst = c :if any ( x :x == c ) good then c else "-" ; 15in stringAsChars subst name ; 16 17serviceUnit = account :{ 18name = escapeUnitName "lieer- ${ account . name } " ; 19value = { 20Unit = { 21Description = "lieer Gmail synchronization for ${ account . name } " ; 22ConditionPathExists = " ${ account . maildir . absPath } /.gmailieer.json" ; 23}; 24 25Service = { 26Type = "oneshot" ; 27ExecStart = " ${ config . programs . lieer . package } /bin/gmi sync" ; 28WorkingDirectory = account . maildir . absPath ; 29Environment = 30"NOTMUCH_CONFIG= ${ config . xdg . configHome } /notmuch/default/config" ; 31}; 32}; 33}; 34 35timerUnit = account :{ 36name = escapeUnitName "lieer- ${ account . name } " ; 37value = { 38Unit = { 39Description = "lieer Gmail synchronization for ${ account . name } " ; 40}; 41 42Timer = { 43OnCalendar = account . lieer . sync . frequency ; 44RandomizedDelaySec = 30 ; 45}; 46 47Install = { WantedBy = [ "timers.target" ]; }; 48}; 49}; 50 51in { 52meta . maintainers = [ maintainers . tadfisher ]; 53 54options . services . lieer . enable = 55mkEnableOption "lieer Gmail synchronization service" ; 56 57config = mkIf cfg . enable { 58assertions = [ 59( lib . hm . assertions . assertPlatform "services.lieer" pkgs 60lib . platforms . linux ) 61]; 62 63programs . lieer . enable = true ; 64systemd . user . services = listToAttrs ( map serviceUnit syncAccounts ); 65systemd . user . timers = listToAttrs ( map timerUnit syncAccounts ); 66}; 67}