2020-12-21 01:37:55 +00:00
|
|
|
{ pkgs, lib, ... }:
|
|
|
|
let
|
2021-05-18 14:33:28 +00:00
|
|
|
addressbooks = pkgs.privateValue [ ] "addressbooks";
|
|
|
|
calendars = pkgs.privateValue [ ] "calendars";
|
2020-12-21 01:37:55 +00:00
|
|
|
mkConfig = config:
|
2021-05-18 14:33:28 +00:00
|
|
|
(pkgs.formats.ini { }).generate "vdirsyncer-config" (
|
2021-02-14 20:19:25 +00:00
|
|
|
lib.mapAttrs
|
|
|
|
(
|
|
|
|
name: section:
|
|
|
|
(lib.mapAttrs (name: option: builtins.toJSON option) section)
|
2021-05-18 14:33:28 +00:00
|
|
|
)
|
|
|
|
config
|
2021-02-14 20:19:25 +00:00
|
|
|
);
|
2021-04-12 13:41:05 +00:00
|
|
|
mkCalendar = { name, url, username, passwordPath, collections ? [ "from a" "from b" ], readOnly ? false, type ? "caldav" }:
|
2020-12-21 01:37:55 +00:00
|
|
|
let
|
|
|
|
pairName = "${name}_calendar";
|
|
|
|
remoteName = "${pairName}_remote";
|
|
|
|
localName = "${pairName}_local";
|
2021-02-14 20:19:25 +00:00
|
|
|
in
|
2021-05-18 14:33:28 +00:00
|
|
|
{
|
|
|
|
"pair ${pairName}" = {
|
|
|
|
a = localName;
|
|
|
|
b = remoteName;
|
|
|
|
inherit collections;
|
|
|
|
conflict_resolution = "b wins";
|
|
|
|
metadata = [ "color" ];
|
2020-12-21 01:37:55 +00:00
|
|
|
};
|
2021-05-18 14:33:28 +00:00
|
|
|
"storage ${localName}" = {
|
|
|
|
type = "filesystem";
|
|
|
|
path = "~/.calendars/${name}/";
|
|
|
|
fileext = ".ics";
|
|
|
|
};
|
|
|
|
"storage ${remoteName}" = {
|
|
|
|
inherit type;
|
|
|
|
inherit url;
|
|
|
|
} // (if (type == "caldav") then {
|
|
|
|
inherit username;
|
|
|
|
"password.fetch" = [ "command" "${pkgs.pass}/bin/pass" passwordPath ];
|
|
|
|
read_only = readOnly;
|
|
|
|
} else { });
|
|
|
|
};
|
2021-02-14 20:19:25 +00:00
|
|
|
mkAddressbook = { name, url, username, passwordPath, collections ? [ "from a" "from b" ], readOnly ? false }:
|
2020-12-21 01:37:55 +00:00
|
|
|
let
|
|
|
|
pairName = "${name}_contacts";
|
|
|
|
remoteName = "${pairName}_remote";
|
|
|
|
localName = "${pairName}_local";
|
2021-02-14 20:19:25 +00:00
|
|
|
in
|
2021-05-18 14:33:28 +00:00
|
|
|
{
|
|
|
|
"pair ${pairName}" = {
|
|
|
|
a = localName;
|
|
|
|
b = remoteName;
|
|
|
|
inherit collections;
|
|
|
|
conflict_resolution = "b wins";
|
|
|
|
};
|
|
|
|
"storage ${localName}" = {
|
|
|
|
type = "filesystem";
|
|
|
|
path = "~/.contacts/${name}/";
|
|
|
|
fileext = ".vcf";
|
2020-12-21 01:37:55 +00:00
|
|
|
};
|
2021-05-18 14:33:28 +00:00
|
|
|
"storage ${remoteName}" = {
|
|
|
|
type = "carddav";
|
|
|
|
inherit url username;
|
|
|
|
"password.fetch" = [ "command" "${pkgs.pass}/bin/pass" passwordPath ];
|
|
|
|
read_only = readOnly;
|
|
|
|
};
|
|
|
|
};
|
2021-02-14 20:19:25 +00:00
|
|
|
in
|
|
|
|
{
|
2020-12-21 01:37:55 +00:00
|
|
|
home = {
|
|
|
|
packages = [ pkgs.vdirsyncer ];
|
|
|
|
file.".config/vdirsyncer/config".source = mkConfig
|
2021-02-14 20:19:25 +00:00
|
|
|
(
|
2021-05-18 14:33:28 +00:00
|
|
|
pkgs.lib.fold (a: b: a // b)
|
|
|
|
{
|
|
|
|
general.status_path = "~/.vdirsyncer/status";
|
|
|
|
}
|
|
|
|
(map mkCalendar calendars ++ map mkAddressbook addressbooks)
|
2021-02-14 20:19:25 +00:00
|
|
|
);
|
2020-12-21 01:37:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
systemd.user = {
|
|
|
|
services.vdirsyncer = {
|
|
|
|
Unit.Description = "vdirsyncer sync";
|
|
|
|
Service = {
|
|
|
|
Type = "oneshot";
|
|
|
|
ExecStart = "${pkgs.vdirsyncer}/bin/vdirsyncer sync";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
timers.vdirsyncer = {
|
|
|
|
Unit.Description = "vdirsync sync timer";
|
|
|
|
Timer.OnCalendar = "*:0/15";
|
|
|
|
Install.WantedBy = [ "timers.target" ];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|