allow multiple calendars with override of tentative detection
1 file changed, 67 insertions(+), 21 deletions(-)
changed files
M flake.nix → flake.nix
@@ -123,6 +123,34 @@ cfg = config.services.mycal; settingsFormat = pkgs.formats.toml { }; inherit (lib) mkEnableOption mkOption mkIf types; + + calendarOptionType = types.submodule { + options = { + file = mkOption { + type = with types; nullOr str; + default = ""; + example = "/path/to/calendar/file"; + description = '' + Path to the calendar file. Preferred over URL. + ''; + }; + url = mkOption { + type = with types; nullOr str; + default = ""; + example = "https://example.com/calendar.ics"; + description = '' + URL to the calendar file. + ''; + }; + all_tentative = mkOption { + type = types.bool; + default = false; + description = '' + Whether all events from this calendar should be marked as tentative. + ''; + }; + }; + }; in { options.services.mycal = {@@ -179,28 +207,31 @@ calendar = mkOption { default = { }; description = '' - Configuration for the calendar. Either a file or a URL must be provided. + Configuration for a single calendar. Either a file or a URL must be provided. + This option is kept for backward compatibility. Using the calendars option + is recommended for new configurations. + + Note: This option is deprecated and will be removed in a future release. ''; - type = types.submodule { - options = { - file = mkOption { - type = types.str; - default = ""; - example = "/path/to/calendar/file"; - description = '' - Path to the calendar file. Preferred over URL. - ''; - }; - url = mkOption { - type = types.str; - default = ""; - example = "https://example.com/calendar.ics"; - description = '' - URL to the calendar file. - ''; - }; - }; - }; + type = calendarOptionType; + }; + + calendars = mkOption { + default = [ ]; + description = '' + Configuration for multiple calendars. This option will be appended to the + singular calendar option if both are specified. + ''; + type = types.listOf calendarOptionType; + }; + + email = mkOption { + type = types.str; + default = ""; + example = "john.doe@example.com"; + description = '' + Email address of the user. + ''; }; }; };@@ -208,6 +239,21 @@ }; }; config = mkIf cfg.enable { + # Validate configuration + assertions = [ + { + assertion = with cfg.settings; + (calendars != [ ] && builtins.any (cal: cal.file != "" || cal.url != "") calendars) || + (calendar.file != "" || calendar.url != ""); + message = "At least one calendar must be configured with either a file or URL in either settings.calendar or settings.calendars"; + } + ]; + + # Issue deprecation warning if the calendar option is used + warnings = lib.optional + (cfg.settings.calendar.file != "" || cfg.settings.calendar.url != "") + "The settings.calendar option is deprecated and will be removed in a future release. Please use the settings.calendars option instead."; + systemd.services.mycal = { description = "Mycal Calendar Service";