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
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
{
home.packages = with pkgs; [
@ -10,54 +52,40 @@ in
];
xdg.configFile = {
"vdirsyncer/config".text = /* ini */ ''
[general]
status_path = "${config.xdg.configHome}/vdirsyncer/status/"
[pair contacts]
a = "contacts_local"
b = "contacts_remote"
collections = ["from a", "from b"]
metadata = ["displayname"]
[storage contacts_local]
type = "filesystem"
path = "~/.contacts/"
fileext = ".vcf"
[storage contacts_remote]
type = "carddav"
url = "https://dav.sbruder.de/"
username = "simon@sbruder.de"
password.fetch = ["command", "sh", "-c", "pass sbruder.de/mail | head -n 1"]
[pair calendar]
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"]
'';
"vdirsyncer/config".text = lib.generators.toINI
{
mkKeyValue = k: v: "${k} = ${builtins.toJSON v}";
}
({
general = {
status_path = "${config.xdg.configHome}/vdirsyncer/status/";
};
} // lib.foldl lib.mergeAttrs { } [
(mkDavSection {
type = "contacts";
name = "personal";
url = "https://dav.sbruder.de/";
username = "simon@sbruder.de";
passwordCommand = "pass sbruder.de/mail | head -n 1";
})
(mkDavSection {
type = "calendar";
name = "personal";
url = "https://dav.sbruder.de/";
username = "simon@sbruder.de";
passwordCommand = "pass sbruder.de/mail | head -n 1";
})
]);
"khal/config".text = /* toml */ ''
[calendars]
[[calendar_local]]
path = ~/.calendar/*
[[calendar_personal]]
path = ${calendarBasePath}/personal/*
type = discover
[[contacts_local]]
path = ~/.contacts/${contactsUuid}/
[[contacts_personal]]
path = ${contactsBasePath}/personal/${personalContactsUuid}/
type = birthdays
[locale]
@ -71,7 +99,7 @@ in
"khard/khard.conf".text = /* toml */ ''
[addressbooks]
[[personal]]
path = ~/.contacts/${contactsUuid}/
path = ${contactsBasePath}/personal/${personalContactsUuid}/
[general]
debug = no