fork/home-manager
git clone https://git.julia.blue/fork/home-manager
75790441
master
1{ config , lib , pkgs , ...} : 2 3with lib ; 4 5let 6 7cfg = config . services . mbsync ; 8 9mbsyncOptions = [ "--all" ] ++ optional ( cfg . verbose ) "--verbose" 10++ optional ( cfg . configFile != null ) "--config ${ cfg . configFile } " ; 11 12in { 13meta . maintainers = [ maintainers . pjones ]; 14 15options . services . mbsync = { 16enable = mkEnableOption "mbsync" ; 17 18package = mkOption { 19type = types . package ; 20default = pkgs . isync ; 21defaultText = literalExpression "pkgs.isync" ; 22example = literalExpression "pkgs.isync" ; 23description = "The package to use for the mbsync binary." ; 24}; 25 26frequency = mkOption { 27type = types . str ; 28default = "*:0/5" ; 29description = '' 30How often to run mbsync. This value is passed to the systemd 31timer configuration as the onCalendar option. See 32{manpage}`systemd.time(7)` 33for more information about the format. 34'' ; 35}; 36 37verbose = mkOption { 38type = types . bool ; 39default = true ; 40description = '' 41Whether mbsync should produce verbose output. 42'' ; 43}; 44 45configFile = mkOption { 46type = types . nullOr types . path ; 47default = null ; 48description = '' 49Optional configuration file to link to use instead of 50the default file ({file}`~/.mbsyncrc`). 51'' ; 52}; 53 54preExec = mkOption { 55type = types . nullOr types . str ; 56default = null ; 57example = "mkdir -p %h/mail" ; 58description = '' 59An optional command to run before mbsync executes. This is 60useful for creating the directories mbsync is going to use. 61'' ; 62}; 63 64postExec = mkOption { 65type = types . nullOr types . str ; 66default = null ; 67example = "\${pkgs.mu}/bin/mu index" ; 68description = '' 69An optional command to run after mbsync executes successfully. 70This is useful for running mailbox indexing tools. 71'' ; 72}; 73}; 74 75config = mkIf cfg . enable { 76assertions = [ 77( lib . hm . assertions . assertPlatform "services.mbsync" pkgs 78lib . platforms . linux ) 79]; 80 81systemd . user . services . mbsync = { 82Unit = { Description = "mbsync mailbox synchronization" ; }; 83 84Service = { 85Type = "oneshot" ; 86ExecStart = 87" ${ cfg . package } /bin/mbsync ${ concatStringsSep " " mbsyncOptions } " ; 88} // ( optionalAttrs ( cfg . postExec != null ) { 89ExecStartPost = cfg . postExec ; 90}) // ( optionalAttrs ( cfg . preExec != null ) { 91ExecStartPre = cfg . preExec ; 92}); 93}; 94 95systemd . user . timers . mbsync = { 96Unit = { Description = "mbsync mailbox synchronization" ; }; 97 98Timer = { 99OnCalendar = cfg . frequency ; 100Unit = "mbsync.service" ; 101}; 102 103Install = { WantedBy = [ "timers.target" ]; }; 104}; 105}; 106}