fork/home-manager

git clone https://git.julia.blue/fork/home-manager

Thibaut Martynotmuch: fix database creation when using hooks6d9d9294

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