thunderbird: support declaration of calendars

Adds calendar support using the `accounts.calendar.accounts.*` options.
This commit is contained in:
DerRockWolf 2024-06-02 11:19:24 +02:00
parent 0eb314b4f0
commit 32f243ef02
No known key found for this signature in database
5 changed files with 160 additions and 9 deletions

View file

@ -1656,6 +1656,15 @@ in {
See https://codeberg.org/dnkl/yambar for more.
'';
}
{
time = "2024-06-02T17:00:00+00:00";
condition = config.programs.thunderbird.enable;
message = ''
'programs.thunderbird' now supports declaration of calendars
using 'accounts.calendar.accounts'.
'';
}
];
};
}

View file

@ -7,11 +7,19 @@ let
cfg = config.programs.thunderbird;
enabledAccounts = attrValues
enabledEmailAccounts = attrValues
(filterAttrs (_: a: a.thunderbird.enable) config.accounts.email.accounts);
enabledAccountsWithId =
map (a: a // { id = builtins.hashString "sha256" a.name; }) enabledAccounts;
enabledEmailAccountsWithId =
map (a: a // { id = builtins.hashString "sha256" a.name; })
enabledEmailAccounts;
enabledCalendarAccounts = attrValues (filterAttrs (_: a: a.thunderbird.enable)
config.accounts.calendar.accounts);
enabledCalendarAccountsWithId =
map (a: a // { id = builtins.hashString "sha256" a.name; })
enabledCalendarAccounts;
thunderbirdConfigPath =
if isDarwin then "Library/Thunderbird" else ".thunderbird";
@ -116,6 +124,32 @@ let
(builtins.map (address: toThunderbirdIdentity account address) addresses)
// account.thunderbird.settings id;
toThunderbirdCalendar = calendar:
let inherit (calendar) id;
in {
"calendar.registry.calendar_${id}.name" = calendar.name;
"calendar.registry.calendar_${id}.calendar-main-in-composite" = true;
"calendar.registry.calendar_${id}.cache.enabled" = true;
} // optionalAttrs (calendar.remote == null) {
"calendar.registry.calendar_${id}.type" = "storage";
"calendar.registry.calendar_${id}.uri" = "moz-storage-calendar://";
} // optionalAttrs (calendar.remote != null) {
"calendar.registry.calendar_${id}.type" =
# TODO: assert if remote.type is google_calendar
if (calendar.remote.type == "http") then
"ics"
else
calendar.remote.type;
"calendar.registry.calendar_${id}.uri" = calendar.remote.url;
"calendar.registry.calendar_${id}.username" = calendar.remote.userName;
} // optionalAttrs calendar.primary {
"calendar.registry.calendar_${id}.calendar-main-default" = true;
} // optionalAttrs calendar.thunderbird.readOnly {
"calendar.registry.calendar_${id}.readOnly" = true;
} // optionalAttrs (calendar.thunderbird.color != "") {
"calendar.registry.calendar_${id}.color" = calendar.thunderbird.color;
};
mkUserJs = prefs: extraPrefs: ''
// Generated by Home Manager.
@ -298,6 +332,41 @@ in {
};
});
};
accounts.calendar.accounts = mkOption {
type = with types;
attrsOf (submodule {
options.thunderbird = {
enable =
mkEnableOption "the Thunderbird mail client for this account";
profiles = mkOption {
type = with types; listOf str;
default = [ ];
example = literalExpression ''
[ "profile1" "profile2" ]
'';
description = ''
List of Thunderbird profiles for which this account should be
enabled. If this list is empty (the default), this account will
be enabled for all declared profiles.
'';
};
readOnly = mkOption {
type = bool;
default = false;
description = "Mark calendar as read only";
};
color = mkOption {
type = str;
default = "";
example = "#dc8add";
description = "Display color of the calendar in hex";
};
};
});
};
};
config = mkIf cfg.enable {
@ -312,8 +381,8 @@ in {
(let
profiles = catAttrs "name" profilesWithId;
selectedProfiles =
concatMap (a: a.thunderbird.profiles) enabledAccounts;
selectedProfiles = concatMap (a: a.thunderbird.profiles)
(enabledEmailAccounts ++ enabledCalendarAccounts);
in {
assertion = (intersectLists profiles selectedProfiles)
== selectedProfiles;
@ -322,6 +391,18 @@ in {
+ ", but the used profiles are "
+ (concatStringsSep "," selectedProfiles);
})
(let
foundCalendars =
filter (a: a.remote != null && a.remote.type == "google_calendar")
enabledCalendarAccounts;
in {
assertion = length foundCalendars == 0;
message = ''
'accounts.calendar.accounts.<name>.remote.type = "google_calendar";' is not supported by Thunderbird, ''
+ "but declared for these calendars: "
+ (concatStringsSep ", " (catAttrs "name" foundCalendars));
})
];
warnings = optional (isDarwin && cfg.darwinSetupWarning) ''
@ -353,9 +434,12 @@ in {
mkIf (profile.userContent != "") { text = profile.userContent; };
"${thunderbirdProfilesPath}/${name}/user.js" = let
accounts = filter (a:
f = filter (a:
a.thunderbird.profiles == [ ]
|| any (p: p == name) a.thunderbird.profiles) enabledAccountsWithId;
|| any (p: p == name) a.thunderbird.profiles);
accounts = f enabledEmailAccountsWithId;
calendars = f enabledCalendarAccountsWithId;
smtp = filter (a: a.smtp != null) accounts;
in {
@ -375,8 +459,8 @@ in {
{ "mail.openpgp.allow_external_gnupg" = profile.withExternalGnupg; }
profile.settings
] ++ (map (a: toThunderbirdAccount a profile) accounts)))
profile.extraConfig;
] ++ (map (a: toThunderbirdAccount a profile) accounts)
++ (map toThunderbirdCalendar calendars))) profile.extraConfig;
};
}));
};

View file

@ -1,5 +1,19 @@
// Generated by Home Manager.
user_pref("calendar.registry.calendar_474c12b01f4f765680ac3bb3e0b670b7ac817c9f717997577cac3f12f1b5013a.cache.enabled", true);
user_pref("calendar.registry.calendar_474c12b01f4f765680ac3bb3e0b670b7ac817c9f717997577cac3f12f1b5013a.calendar-main-in-composite", true);
user_pref("calendar.registry.calendar_474c12b01f4f765680ac3bb3e0b670b7ac817c9f717997577cac3f12f1b5013a.name", "holidays");
user_pref("calendar.registry.calendar_474c12b01f4f765680ac3bb3e0b670b7ac817c9f717997577cac3f12f1b5013a.readOnly", true);
user_pref("calendar.registry.calendar_474c12b01f4f765680ac3bb3e0b670b7ac817c9f717997577cac3f12f1b5013a.type", "ics");
user_pref("calendar.registry.calendar_474c12b01f4f765680ac3bb3e0b670b7ac817c9f717997577cac3f12f1b5013a.uri", "https://www.thunderbird.net/media/caldata/autogen/GermanHolidays.ics");
user_pref("calendar.registry.calendar_474c12b01f4f765680ac3bb3e0b670b7ac817c9f717997577cac3f12f1b5013a.username", null);
user_pref("calendar.registry.calendar_5152790e278eb89039f8bfaa354b944ec1b44c5d3fc144edc5720c3edc045c73.cache.enabled", true);
user_pref("calendar.registry.calendar_5152790e278eb89039f8bfaa354b944ec1b44c5d3fc144edc5720c3edc045c73.calendar-main-default", true);
user_pref("calendar.registry.calendar_5152790e278eb89039f8bfaa354b944ec1b44c5d3fc144edc5720c3edc045c73.calendar-main-in-composite", true);
user_pref("calendar.registry.calendar_5152790e278eb89039f8bfaa354b944ec1b44c5d3fc144edc5720c3edc045c73.name", "calendar");
user_pref("calendar.registry.calendar_5152790e278eb89039f8bfaa354b944ec1b44c5d3fc144edc5720c3edc045c73.type", "caldav");
user_pref("calendar.registry.calendar_5152790e278eb89039f8bfaa354b944ec1b44c5d3fc144edc5720c3edc045c73.uri", "https://my.caldav.server/calendar");
user_pref("calendar.registry.calendar_5152790e278eb89039f8bfaa354b944ec1b44c5d3fc144edc5720c3edc045c73.username", "testuser");
user_pref("general.useragent.override", "");
user_pref("mail.account.account_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc.identities", "id_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc");
user_pref("mail.account.account_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc.server", "server_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc");

View file

@ -1,5 +1,17 @@
// Generated by Home Manager.
user_pref("calendar.registry.calendar_25bf8e1a2393f1108d37029b3df5593236c755742ec93465bbafa9b290bddcf6.cache.enabled", true);
user_pref("calendar.registry.calendar_25bf8e1a2393f1108d37029b3df5593236c755742ec93465bbafa9b290bddcf6.calendar-main-in-composite", true);
user_pref("calendar.registry.calendar_25bf8e1a2393f1108d37029b3df5593236c755742ec93465bbafa9b290bddcf6.name", "local");
user_pref("calendar.registry.calendar_25bf8e1a2393f1108d37029b3df5593236c755742ec93465bbafa9b290bddcf6.type", "storage");
user_pref("calendar.registry.calendar_25bf8e1a2393f1108d37029b3df5593236c755742ec93465bbafa9b290bddcf6.uri", "moz-storage-calendar://");
user_pref("calendar.registry.calendar_474c12b01f4f765680ac3bb3e0b670b7ac817c9f717997577cac3f12f1b5013a.cache.enabled", true);
user_pref("calendar.registry.calendar_474c12b01f4f765680ac3bb3e0b670b7ac817c9f717997577cac3f12f1b5013a.calendar-main-in-composite", true);
user_pref("calendar.registry.calendar_474c12b01f4f765680ac3bb3e0b670b7ac817c9f717997577cac3f12f1b5013a.name", "holidays");
user_pref("calendar.registry.calendar_474c12b01f4f765680ac3bb3e0b670b7ac817c9f717997577cac3f12f1b5013a.readOnly", true);
user_pref("calendar.registry.calendar_474c12b01f4f765680ac3bb3e0b670b7ac817c9f717997577cac3f12f1b5013a.type", "ics");
user_pref("calendar.registry.calendar_474c12b01f4f765680ac3bb3e0b670b7ac817c9f717997577cac3f12f1b5013a.uri", "https://www.thunderbird.net/media/caldata/autogen/GermanHolidays.ics");
user_pref("calendar.registry.calendar_474c12b01f4f765680ac3bb3e0b670b7ac817c9f717997577cac3f12f1b5013a.username", null);
user_pref("general.useragent.override", "");
user_pref("mail.account.account_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc.identities", "id_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc");
user_pref("mail.account.account_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc.server", "server_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc");

View file

@ -35,6 +35,38 @@
};
};
accounts.calendar.accounts = {
calendar = {
thunderbird = {
enable = true;
profiles = [ "first" ];
};
primary = true;
remote = {
type = "caldav";
url = "https://my.caldav.server/calendar";
userName = "testuser";
};
};
holidays = {
thunderbird = {
enable = true;
readOnly = true;
};
remote = {
type = "http";
url =
"https://www.thunderbird.net/media/caldata/autogen/GermanHolidays.ics";
};
};
local = {
thunderbird = {
enable = true;
profiles = [ "second" ];
};
};
};
programs.thunderbird = {
enable = true;