# CLI calendar application (khal) { config, lib, pkgs, ... }: let cfg = config.office.khal; icons = config.desktop.icons.apps; calendarPath = "${config.xdg.dataHome}/khal/calendars"; base16Colors = import ../../colors/base16 { inherit config lib pkgs; }; calendarNames = builtins.attrNames cfg.calendars; usableColors = with base16Colors.colorsWithHashPrefix; [ base08 base09 base0A base0B base0C base0D base0E base0F ]; calendarColors = builtins.listToAttrs ( lib.imap0 (index: name: { inherit name; value = builtins.elemAt usableColors (lib.mod index (builtins.length usableColors)); }) calendarNames ); in { imports = [ ./assertions.nix ]; options.office.khal = { enable = lib.mkEnableOption "khal, a CLI calendar application"; package = lib.mkOption { type = lib.types.package; readOnly = true; default = config.programs.khal.package; description = "The khal package to use."; }; calendars = lib.mkOption { type = lib.types.attrsOf ( lib.types.submodule ( { name, ... }: { options = { read-only = lib.mkOption { type = lib.types.bool; default = false; description = "Whether khal may modify this calendar."; }; primary = lib.mkOption { type = lib.types.bool; default = name == "personal"; description = "Whether khal should use this calendar for new events by default."; }; }; } ) ); default.personal = { }; description = "Named vdir calendars managed by khal."; }; }; config = lib.mkIf cfg.enable { programs.khal = { enable = true; locale = { timeformat = "%H:%M"; dateformat = "%Y-%m-%d"; longdateformat = "%Y-%m-%d"; datetimeformat = "%Y-%m-%d %H:%M"; longdatetimeformat = "%Y-%m-%d %H:%M"; }; settings.default = { default_dayevent_duration = "1d"; default_event_duration = "1h"; enable_mouse = true; highlight_event_days = false; timedelta = "2d"; }; settings.view.theme = "dark"; }; accounts.calendar = { basePath = calendarPath; accounts = lib.mapAttrs (_name: calendar: { primary = calendar.primary; khal = { enable = true; color = calendarColors.${_name}; readOnly = calendar.read-only; }; local = { path = "${calendarPath}/${_name}"; type = "filesystem"; }; }) cfg.calendars; }; xdg.desktopEntries."khal" = lib.mkIf (config.terminal.kitty.enable && cfg.package != null) { name = "khal"; exec = "${lib.getExe config.terminal.kitty.package} --class khal -e ${lib.getExe' cfg.package "khal"} interactive"; icon = icons.khal or "calendar"; categories = [ "Office" "Calendar" ]; comment = "CLI calendar application"; terminal = false; type = "Application"; }; }; }