1
0
Fork 0
nixos-config/home-manager/roles/vdirsyncer.nix
2020-12-21 02:38:15 +01:00

78 lines
2.3 KiB
Nix

{ pkgs, lib, ... }:
let
addressbooks = pkgs.privateValue [ ] "addressbooks";
calendars = pkgs.privateValue [ ] "calendars";
mkConfig = config:
(pkgs.formats.ini { }).generate "vdirsyncer-config" (lib.mapAttrs
(name: section:
(lib.mapAttrs (name: option: builtins.toJSON option) section)) config);
mkCalendar = { name, url, username, passwordPath }:
let
pairName = "${name}_calendar";
remoteName = "${pairName}_remote";
localName = "${pairName}_local";
in {
"pair ${pairName}" = {
a = localName;
b = remoteName;
collections = [ "from a" "from b" ];
conflict_resolution = "b wins";
};
"storage ${localName}" = {
type = "filesystem";
path = "~/.calendars/${name}/";
fileext = ".ics";
};
"storage ${remoteName}" = {
type = "caldav";
inherit url username;
"password.fetch" = [ "command" "${pkgs.pass}/bin/pass" passwordPath ];
};
};
mkAddressbook = { name, url, username, passwordPath }:
let
pairName = "${name}_contacts";
remoteName = "${pairName}_remote";
localName = "${pairName}_local";
in {
"pair ${pairName}" = {
a = localName;
b = remoteName;
collections = [ "from a" "from b" ];
conflict_resolution = "b wins";
};
"storage ${localName}" = {
type = "filesystem";
path = "~/.contacts/${name}/";
fileext = ".vcf";
};
"storage ${remoteName}" = {
type = "carddav";
inherit url username;
"password.fetch" = [ "command" "${pkgs.pass}/bin/pass" passwordPath ];
};
};
in {
home = {
packages = [ pkgs.vdirsyncer ];
file.".config/vdirsyncer/config".source = mkConfig
(pkgs.lib.fold (a: b: a // b) {
general.status_path = "~/.vdirsyncer/status";
} (map mkCalendar calendars ++ map mkAddressbook addressbooks));
};
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" ];
};
};
}