fork/home-manager

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

Robert HelgessonMerge PR #421575790441

master
2.2 KiB86 linesraw
1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6
7  cfg = config.services.vdirsyncer;
8
9  vdirsyncerOptions = [ ]
10    ++ optional (cfg.verbosity != null) "--verbosity ${cfg.verbosity}"
11    ++ optional (cfg.configFile != null) "--config ${cfg.configFile}";
12
13in {
14  meta.maintainers = [ maintainers.pjones ];
15
16  options.services.vdirsyncer = {
17    enable = mkEnableOption "vdirsyncer";
18
19    package = mkOption {
20      type = types.package;
21      default = pkgs.vdirsyncer;
22      defaultText = "pkgs.vdirsyncer";
23      example = literalExpression "pkgs.vdirsyncer";
24      description = "The package to use for the vdirsyncer binary.";
25    };
26
27    frequency = mkOption {
28      type = types.str;
29      default = "*:0/5";
30      description = ''
31        How often to run vdirsyncer.  This value is passed to the systemd
32        timer configuration as the onCalendar option.  See
33        {manpage}`systemd.time(7)`
34        for more information about the format.
35      '';
36    };
37
38    verbosity = mkOption {
39      type = types.nullOr
40        (types.enum [ "CRITICAL" "ERROR" "WARNING" "INFO" "DEBUG" ]);
41      default = null;
42      description = ''
43        Whether vdirsyncer should produce verbose output.
44      '';
45    };
46
47    configFile = mkOption {
48      type = types.nullOr types.path;
49      default = null;
50      description = ''
51        Optional configuration file to link to use instead of
52        the default file ({file}`$XDG_CONFIG_HOME/vdirsyncer/config`).
53      '';
54    };
55  };
56
57  config = mkIf cfg.enable {
58    systemd.user.services.vdirsyncer = {
59      Unit = {
60        Description = "vdirsyncer calendar&contacts synchronization";
61        PartOf = [ "network-online.target" ];
62      };
63
64      Service = {
65        Type = "oneshot";
66        # TODO `vdirsyncer discover`
67        ExecStart = let optStr = concatStringsSep " " vdirsyncerOptions;
68        in [
69          "${cfg.package}/bin/vdirsyncer ${optStr} metasync"
70          "${cfg.package}/bin/vdirsyncer ${optStr} sync"
71        ];
72      };
73    };
74
75    systemd.user.timers.vdirsyncer = {
76      Unit = { Description = "vdirsyncer calendar&contacts synchronization"; };
77
78      Timer = {
79        OnCalendar = cfg.frequency;
80        Unit = "vdirsyncer.service";
81      };
82
83      Install = { WantedBy = [ "timers.target" ]; };
84    };
85  };
86}