vdirsyncer: Create abstraction

This commit is contained in:
Simon Bruder 2022-07-07 16:36:00 +02:00
parent d93994e029
commit 1baec2968b
Signed by: simon
GPG key ID: 8D3C82F9F309F8EC

View file

@ -1,6 +1,48 @@
{ config, pkgs, ... }: { config, lib, pkgs, ... }:
let let
contactsUuid = "d6abd3ea-3abd-7550-9f24-f06293d36a82"; contactsBasePath = "${config.xdg.dataHome}/contacts";
calendarBasePath = "${config.xdg.dataHome}/calendar";
personalContactsUuid = "d6abd3ea-3abd-7550-9f24-f06293d36a82";
fetchCommand = command:
if lib.isList command
then [ "command" ] ++ command
else [ "command" "sh" "-c" command ];
mkDavSection = { type, name, url, username, passwordCommand }: assert builtins.elem type [ "contacts" "calendar" ]; let
id = "${type}_${name}";
basePath = {
"contacts" = contactsBasePath;
"calendar" = calendarBasePath;
}.${type};
in
{
"pair ${id}" = {
a = "${id}_local";
b = "${id}_remote";
collections = [ "from a" "from b" ];
metadata = [ "displayname" ];
};
"storage ${id}_local" = {
type = "filesystem";
path = "${basePath}/${name}/";
fileext = {
contacts = ".vcf";
calendar = ".ics";
}.${type};
};
"storage ${id}_remote" = {
type = {
"calendar" = "caldav";
"contacts" = "carddav";
}.${type};
inherit url username;
"password.fetch" = fetchCommand passwordCommand;
};
};
in in
{ {
home.packages = with pkgs; [ home.packages = with pkgs; [
@ -10,54 +52,40 @@ in
]; ];
xdg.configFile = { xdg.configFile = {
"vdirsyncer/config".text = /* ini */ '' "vdirsyncer/config".text = lib.generators.toINI
[general] {
status_path = "${config.xdg.configHome}/vdirsyncer/status/" mkKeyValue = k: v: "${k} = ${builtins.toJSON v}";
}
[pair contacts] ({
a = "contacts_local" general = {
b = "contacts_remote" status_path = "${config.xdg.configHome}/vdirsyncer/status/";
collections = ["from a", "from b"] };
metadata = ["displayname"] } // lib.foldl lib.mergeAttrs { } [
(mkDavSection {
[storage contacts_local] type = "contacts";
type = "filesystem" name = "personal";
path = "~/.contacts/" url = "https://dav.sbruder.de/";
fileext = ".vcf" username = "simon@sbruder.de";
passwordCommand = "pass sbruder.de/mail | head -n 1";
[storage contacts_remote] })
type = "carddav" (mkDavSection {
url = "https://dav.sbruder.de/" type = "calendar";
username = "simon@sbruder.de" name = "personal";
password.fetch = ["command", "sh", "-c", "pass sbruder.de/mail | head -n 1"] url = "https://dav.sbruder.de/";
username = "simon@sbruder.de";
[pair calendar] passwordCommand = "pass sbruder.de/mail | head -n 1";
a = "calendar_local" })
b = "calendar_remote" ]);
collections = ["from a", "from b"]
metadata = ["displayname"]
[storage calendar_local]
type = "filesystem"
path = "~/.calendar/"
fileext = ".ics"
[storage calendar_remote]
type = "caldav"
url = "https://dav.sbruder.de/"
username = "simon@sbruder.de"
password.fetch = ["command", "sh", "-c", "pass sbruder.de/mail | head -n 1"]
'';
"khal/config".text = /* toml */ '' "khal/config".text = /* toml */ ''
[calendars] [calendars]
[[calendar_local]] [[calendar_personal]]
path = ~/.calendar/* path = ${calendarBasePath}/personal/*
type = discover type = discover
[[contacts_local]] [[contacts_personal]]
path = ~/.contacts/${contactsUuid}/ path = ${contactsBasePath}/personal/${personalContactsUuid}/
type = birthdays type = birthdays
[locale] [locale]
@ -71,7 +99,7 @@ in
"khard/khard.conf".text = /* toml */ '' "khard/khard.conf".text = /* toml */ ''
[addressbooks] [addressbooks]
[[personal]] [[personal]]
path = ~/.contacts/${contactsUuid}/ path = ${contactsBasePath}/personal/${personalContactsUuid}/
[general] [general]
debug = no debug = no