Use generators for vdirsyncer, khal and hkard configs instead of huge strings

This commit is contained in:
Charlotte Van Petegem 2020-10-17 00:05:57 +02:00
parent e0295a239e
commit fbdf99204a
No known key found for this signature in database
GPG key ID: 019E764B7184435A

View file

@ -63,6 +63,20 @@ let
}; };
}; };
}; };
repeat = count: char: lib.strings.concatStrings (builtins.genList (_: char) count);
mkHeader = depth: name: lib.strings.concatStrings [ (repeat depth "[") name (repeat depth "]") ];
simpleAttrs = lib.attrsets.filterAttrs (n: v: !(builtins.isAttrs v));
complexAttrs = lib.attrsets.filterAttrs (n: v: builtins.isAttrs v);
toRecursiveINIBase = depth: data: (builtins.concatStringsSep "\n" (
lib.attrsets.mapAttrsToList
(name: values: builtins.concatStringsSep "\n" (builtins.filter (v: v != "") [
(mkHeader depth name)
(lib.generators.toKeyValue { } (simpleAttrs values))
(toRecursiveINIBase (depth + 1) (complexAttrs values))
]))
data
));
toRecursiveINI = toRecursiveINIBase 1;
in in
{ {
custom.zfs.homeLinks = [ custom.zfs.homeLinks = [
@ -171,105 +185,85 @@ in
''; '';
}; };
xdg.configFile = { xdg.configFile = {
"khal/config".text = '' "khal/config".text = toRecursiveINI {
[calendars] calendars = {
calendar = {
[[calendar]] path = "~/.local/share/calendars/*";
path = ~/.local/share/calendars/* type = "discover";
type = discover };
};
[locale] locale = {
timeformat = %H:%M timeformat = "%H:%M";
dateformat = %Y-%m-%d dateformat = "%Y-%m-%d";
longdateformat = %Y-%m-%d longdateformat = "%Y-%m-%d";
datetimeformat = %Y-%m-%d %H:%M datetimeformat = "%Y-%m-%d %H:%M";
longdatetimeformat = %Y-%m-%d %H:%M longdatetimeformat = "%Y-%m-%d %H:%M";
''; };
"khard/khard.conf".text = '' };
[addressbooks] "khard/khard.conf".text = toRecursiveINI {
[[contacts]] addressbooks = {
path = ~/.local/share/contacts/contacts contacts = {
path = "~/.local/share/contacts/contacts";
[general] };
debug = no };
default_action = list general = {
# These are either strings or comma seperated lists debug = "no";
editor = nvim default_action = "list";
merge_editor = nvim, -d editor = "nvim";
merge_editor = "nvim, -d";
[contact table] };
# display names by first or last name: first_name / last_name / formatted_name "contact table" = {
display = formatted_name display = "formatted_name";
# group by address book: yes / no group_by_addressbook = "no";
group_by_addressbook = no reverse = "no";
# reverse table ordering: yes / no show_nicknames = "no";
reverse = no show_uids = "yes";
# append nicknames to name column: yes / no sort = "last_name";
show_nicknames = no localize_dates = "yes";
# show uid table column: yes / no preferred_phone_number_type = "pref, cell, home";
show_uids = yes preferred_email_address_type = "pref, work, home";
# sort by first or last name: first_name / last_name / formatted_name };
sort = last_name vcard = {
# localize dates: yes / no private_objects = ",";
localize_dates = yes preferred_version = "4.0";
# set a comma separated list of preferred phone number types in descending priority search_in_source_files = "no";
# or nothing for non-filtered alphabetical order skip_unparsable = "no";
preferred_phone_number_type = pref, cell, home };
# set a comma separated list of preferred email address types in descending priority };
# or nothing for non-filtered alphabetical order "vdirsyncer/config".text =
preferred_email_address_type = pref, work, home let nextcloudConfig = type: {
inherit type;
[vcard] url = "https://nextcloud.vanpetegem.me";
# extend contacts with your own private objects username = "chvp";
# these objects are stored with a leading "X-" before the object name in the vcard files "password.fetch" = [ "command" "${passwordScript}" "social/Nextcloud" ];
# every object label may only contain letters, digits and the - character }; in
# example: lib.generators.toINI
# private_objects = Jabber, Skype, Twitter { mkKeyValue = lib.generators.mkKeyValueDefault { mkValueString = builtins.toJSON; } "="; }
# default: , (the empty list) {
private_objects = , general.status_path = "~/.local/share/vdirsyncer";
# preferred vcard version: 3.0 / 4.0 "pair nextcloud_contacts" = {
preferred_version = 4.0 a = "nextcloud_contacts_local";
# Look into source vcf files to speed up search queries: yes / no b = "nextcloud_contacts_remote";
search_in_source_files = no collections = [ "from a" "from b" ];
# skip unparsable vcard files: yes / no };
skip_unparsable = no "storage nextcloud_contacts_local" = {
''; type = "filesystem";
"vdirsyncer/config".text = '' path = "~/.local/share/contacts";
[general] fileext = ".vcf";
status_path = "~/.local/share/vdirsyncer" };
"storage nextcloud_contacts_remote" = nextcloudConfig "carddav";
[pair nextcloud_contacts] "pair nextcloud_calendars" = {
a = "nextcloud_contacts_local" a = "nextcloud_calendars_local";
b = "nextcloud_contacts_remote" b = "nextcloud_calendars_remote";
collections = ["from a", "from b"] collections = [ "from a" "from b" ];
};
[storage nextcloud_contacts_local] "storage nextcloud_calendars_local" = {
type = "filesystem" type = "filesystem";
path = "~/.local/share/contacts" path = "~/.local/share/calendars";
fileext = ".vcf" fileext = ".ics";
};
[storage nextcloud_contacts_remote] "storage nextcloud_calendars_remote" = nextcloudConfig "caldav";
type = "carddav" };
url = "https://nextcloud.vanpetegem.me/"
username = "chvp"
password.fetch = ["command", "${passwordScript}", "social/Nextcloud"]
[pair nextcloud_calendars]
a = "nextcloud_calendars_local"
b = "nextcloud_calendars_remote"
collections = ["from a", "from b"]
[storage nextcloud_calendars_local]
type = "filesystem"
path = "~/.local/share/calendars"
fileext = ".ics"
[storage nextcloud_calendars_remote]
type = "caldav"
url = "https://nextcloud.vanpetegem.me/"
username = "chvp"
password.fetch = ["command", "${passwordScript}", "social/Nextcloud"]
'';
}; };
programs = { programs = {
msmtp.enable = true; msmtp.enable = true;