{ pkgs, config, age, ... }:

{
  home.packages = with pkgs; [
    khal
    khard
    vdirsyncer
  ];

  xdg.configFile = {
    "vdirsyncer/config".text = ''
      [general]
      status_path = "/home/anish/.config/vdirsyncer/status/" 

      [pair contacts]
      a = "contacts_local"
      b = "contacts_remote"
      collections = ["from b"]
      metadata = ["displayname"]

      [storage contacts_local]
      type = "filesystem"
      path = "~/.contacts/"
      fileext = ".vcf"

      [storage contacts_remote]
      type = "carddav"
      url = "http://mossnet.lan:5252/anish"
      username = "anish"
      password.fetch = ["command", "echo", "acceptsanypassword"]

      [pair calendar]
      a = "calendar_local"
      b = "calendar_remote"
      collections = ["from b"]
      metadata = ["displayname"]

      [storage calendar_local]
      type = "filesystem"
      path = "~/.calendar/"
      fileext = ".ics"

      [storage calendar_remote]
      type = "caldav"
      url = "http://mossnet.lan:5252/anish"
      username = "anish"
      password.fetch = ["command", "echo", "allpasswordsaccepted"]
    '';

    "khal/config".text = ''
      [calendars]

      [[calendar_local]]
      path = ~/.calendar/*
      type = discover

      [[contacts_local]]
      path = ~/.contacts/*
      type = birthdays

      [locale]
      timeformat = %H:%M
      dateformat = %Y-%m-%d
      longdateformat = %Y-%m-%d
      datetimeformat = %Y-%m-%d %H:%M
      longdatetimeformat = %Y-%m-%d %H:%M
    '';

    "khard/khard.conf".text = ''
      [addressbooks]
      [[personal]]
      path = ~/.contacts/*

      [general]
      debug = no
      default_action = list
      editor = nvim, -i, NONE
      merge_editor = nvim, -d

      [contact table]
      display = first_name
      group_by_addressbook = no
      reverse = no
      show_nicknames = yes
      show_uids = no
      sort = last_name
      localize_dates = yes
      preferred_phone_number_type = pref, cell, home
      preferred_email_address_type = pref, home, work

      [vcard]
      private_objects = Jabber,
      preferred_version = 3.0
      search_in_source_files = no
      skip_unparsable = no
    '';
  };
}
