{ pkgs, ... }@all: with all; let
  calendars = with hyper; [
    {
      name = "Preservation";
      primary = true;
      url = "https://dav.${domain}/${user}/preservation/";
      color = "#dddddd";
    }
    {
      name = "Effort";
      url = "https://dav.${domain}/${user}/effort/";
      color = "#dd2222";
    }
    {
      name = "Experience";
      url = "https://dav.${domain}/${user}/experience/";
      color = "#2222dd";
    }
    {
      name = "Exposure";
      url = "https://dav.${domain}/${user}/exposure/";
      color = "#22aa22";
    }
    {
      name = "Engagement";
      url = "https://dav.${domain}/${user}/engagement/";
      color = "#8800CC";
    }
    {
      name = "Sleep as Android";
      url = secrets.calendar.sleep-as-android-url;
      color = "#111111";
      read-only = true;
      type = "ics";
    }
    {
      name = "LEC";
      url = "https://${domain}/lec.ics";
      color = "#A87000";
      read-only = true;
      type = "ics";
    }
    {
      name = "LR";
      url = "https://${domain}/lr.ics";
      color = "#005040";
      read-only = true;
      type = "ics";
    }
    {
      name = "Feiertage Hessen";
      url = "https://ics.tools/Feiertage/hessen.ics";
      color = "#303030";
      read-only = true;
      type = "ics";
    }
    # {
    #   name = "Handball Männer";
    #   url = "http://i.cal.to/ical/108/dhb/handball-nationalmannschaft/c687e97f.bc7c3eb6-11a0e356.ics";
    #   color = "#880023";
    #   read-only = true;
    #   type = "ics";
    # }
  ];
  default_set = {
    # name = 
    # url =
    color = "#777777";
    read-only = false;
    primary = false;
    type = "caldav";
  };
in {

  home.packages = with pkgs; [
    gnome-calendar
    thunderbird
  ];

  accounts.calendar.accounts = let
    transform_caledar_set = calendar_set: with calendar_set; { # transform set for accounts.calendar.accounts endpoint
      inherit primary;
      remote = {
        inherit url name;
        userName = hyper.user; # my globally set username
      };
    };
  in lib.attrsets.mergeAttrsList (
    map (calendar: { 
      "${calendar.name}" = transform_caledar_set ( default_set // calendar );
    }) calendars
  );

  programs.thunderbird.settings = let
    to_safe_name = name: (builtins.replaceStrings ["."] ["-"]) name;
  in (lib.attrsets.mergeAttrsList (
    map (calendar: with ( default_set // calendar ); {
      "calendar.registry.${to_safe_name calendar.name}.cache.enabled" = true;
      "calendar.registry.${to_safe_name calendar.name}.calendar-main-default" = primary;
      "calendar.registry.${to_safe_name calendar.name}.calendar-main-in-composite" = true;
      "calendar.registry.${to_safe_name calendar.name}.color" = color;
      "calendar.registry.${to_safe_name calendar.name}.name" = name;
      "calendar.registry.${to_safe_name calendar.name}.type" = type;
      "calendar.registry.${to_safe_name calendar.name}.uri" = url;
      "calendar.registry.${to_safe_name calendar.name}.username" = hyper.user;
      "calendar.registry.${to_safe_name calendar.name}.readOnly" = read-only;
    }) calendars
  ) // {
    "calendar.list.sortOrder" = lib.fold (calendar: acc: calendar.name + " " + acc) "" calendars;
    "calendar.week.start" = 1;
  });
}
