# Synchronize calendars from https://cal.tammena.rocks { pkgs, lib, config, ... }: let cfg = config.services.synchronize-calendars; khalConfig = '' [calendars] [[local]] path = ~/.local/share/calendars/* type = discover [locale] timeformat = %H:%M dateformat = %d.%m.%Y longdateformat = %d.%m.%Y datetimeformat = %d.%m.%Y %H:%M longdatetimeformat = %d.%m.%Y %H:%M [default] default_calendar = ${cfg.defaultCalendar} ''; vdirsyncerConfig = '' [general] status_path = "~/.local/state/vdirsyncer/status/" [pair calendar] a = "calendar_local" b = "calendar_caltammenarocks" collections = ["from a", "from b"] conflict_resolution = "b wins" metadata = ["displayname", "color"] [storage calendar_local] type = "filesystem" path = "~/.local/share/calendars" fileext = ".ics" [storage calendar_caltammenarocks] type = "caldav" url = "https://cal.tammena.rocks/${cfg.user}/" username = "${cfg.user}" password.fetch = ["command", "${pkgs.coreutils}/bin/cat", "${cfg.passwordFile}"] [pair contacts] a = "contacts_local" b = "contacts_caltammenarocks" collections = ["from a", "from b"] conflict_resolution = "b wins" [storage contacts_local] type = "filesystem" path = "~/.local/share/contacts" fileext = ".vcf" [storage contacts_caltammenarocks] type = "carddav" url = "https://cal.tammena.rocks/${cfg.user}" username = "${cfg.user}" password.fetch = ["command", "${pkgs.coreutils}/bin/cat", "${cfg.passwordFile}"] ''; in { options.services.synchronize-calendars = with lib; { enable = mkEnableOption "Enable service to synchronize my calendars and add some necessary programs"; user = mkOption { type = types.str; description = "Radicale user"; }; passwordFile = mkOption { type = types.str; description = "File containing the Radicale password for user"; }; defaultCalendar = mkOption { type = types.str; description = "Default calendar to use in khal"; }; }; config = lib.mkIf cfg.enable { home.packages = [pkgs.vdirsyncer]; # == Systemd settings to automatically run the sync == systemd.user.services."synchronize-calendars" = { Unit.Description = "Synchronize my calendars using vdirsyncer"; Service = { Type = "oneshot"; ExecStart = '' ${pkgs.vdirsyncer}/bin/vdirsyncer sync ''; }; }; systemd.user.timers."synchronize-calendars" = { Unit.Description = "Run synchronize-calendars.service every 15 minutes"; Timer.OnCalendar = "*:0/10"; Install.WantedBy = ["timers.target"]; }; # == Configuration == xdg.configFile."khal/config".text = khalConfig; xdg.configFile."vdirsyncer/config".text = vdirsyncerConfig; }; }