2023-06-12 23:21:24 +02:00
|
|
|
# khal config loader is sensitive to leading space !
|
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.programs.khal;
|
|
|
|
|
|
|
|
khalCalendarAccounts =
|
|
|
|
filterAttrs (_: a: a.khal.enable) config.accounts.calendar.accounts;
|
|
|
|
|
|
|
|
khalContactAccounts = mapAttrs (_: v: v // { type = "birthdays"; })
|
|
|
|
(filterAttrs (_: a: a.khal.enable) config.accounts.contact.accounts);
|
|
|
|
|
|
|
|
khalAccounts = khalCalendarAccounts // khalContactAccounts;
|
|
|
|
|
|
|
|
primaryAccount = findSingle (a: a.primary) null null
|
|
|
|
(mapAttrsToList (n: v: v // { name = n; }) khalAccounts);
|
|
|
|
|
|
|
|
definedAttrs = filterAttrs (_: v: !isNull v);
|
|
|
|
|
|
|
|
toKeyValueIfDefined = attrs: generators.toKeyValue { } (definedAttrs attrs);
|
|
|
|
|
|
|
|
genCalendarStr = name: value:
|
|
|
|
concatStringsSep "\n" ([
|
|
|
|
"[[${name}]]"
|
|
|
|
"path = ${
|
|
|
|
value.local.path + "/"
|
|
|
|
+ (optionalString (value.khal.type == "discover") value.khal.glob)
|
|
|
|
}"
|
|
|
|
] ++ optional (value.khal.readOnly) "readonly = True" ++ [
|
|
|
|
(toKeyValueIfDefined (getAttrs [ "type" "color" "priority" ] value.khal))
|
|
|
|
] ++ [ "\n" ]);
|
|
|
|
|
2023-07-01 00:35:51 +02:00
|
|
|
localeFormatOptions = let
|
|
|
|
T = lib.types;
|
|
|
|
suffix = ''
|
|
|
|
Format strings are for Python `strftime`, similarly to
|
|
|
|
{manpage}`strftime(3)`.
|
|
|
|
'';
|
|
|
|
in {
|
|
|
|
dateformat = mkOption {
|
|
|
|
type = T.str;
|
|
|
|
default = "%x";
|
|
|
|
description = lib.mdDoc ''
|
|
|
|
khal will display and understand all dates in this format.
|
|
|
|
|
|
|
|
${suffix}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
timeformat = mkOption {
|
|
|
|
type = T.str;
|
|
|
|
default = "%X";
|
|
|
|
description = lib.mdDoc ''
|
|
|
|
khal will display and understand all times in this format.
|
|
|
|
|
|
|
|
${suffix}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
datetimeformat = mkOption {
|
|
|
|
type = T.str;
|
|
|
|
default = "%c";
|
|
|
|
description = lib.mdDoc ''
|
|
|
|
khal will display and understand all datetimes in this format.
|
|
|
|
|
|
|
|
${suffix}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
longdateformat = mkOption {
|
|
|
|
type = T.str;
|
|
|
|
default = "%x";
|
|
|
|
description = lib.mdDoc ''
|
|
|
|
khal will display and understand all dates in this format.
|
|
|
|
It should contain a year (e.g. `%Y`).
|
|
|
|
|
|
|
|
${suffix}
|
|
|
|
'';
|
|
|
|
};
|
2023-06-12 23:21:24 +02:00
|
|
|
|
2023-07-01 00:35:51 +02:00
|
|
|
longdatetimeformat = mkOption {
|
|
|
|
type = T.str;
|
|
|
|
default = "%c";
|
|
|
|
description = lib.mdDoc ''
|
|
|
|
khal will display and understand all datetimes in this format.
|
|
|
|
It should contain a year (e.g. `%Y`).
|
|
|
|
|
|
|
|
${suffix}
|
2023-06-12 23:21:24 +02:00
|
|
|
'';
|
|
|
|
};
|
2023-07-01 00:35:51 +02:00
|
|
|
};
|
2023-06-12 23:21:24 +02:00
|
|
|
|
|
|
|
localeOptions = let T = lib.types;
|
|
|
|
in localeFormatOptions // {
|
2023-07-01 00:35:51 +02:00
|
|
|
unicode_symbols = mkOption {
|
2023-06-12 23:21:24 +02:00
|
|
|
type = T.bool;
|
|
|
|
default = true;
|
2023-07-01 00:35:51 +02:00
|
|
|
description = lib.mdDoc ''
|
|
|
|
By default khal uses some Unicode symbols (as in "non-ASCII") as
|
2023-06-12 23:21:24 +02:00
|
|
|
indicators for things like repeating events.
|
|
|
|
If your font, encoding etc. does not support those symbols, set this
|
2023-07-01 00:35:51 +02:00
|
|
|
to false (this will enable ASCII-based replacements).
|
2023-06-12 23:21:24 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2023-07-01 00:35:51 +02:00
|
|
|
default_timezone = mkOption {
|
2023-06-12 23:21:24 +02:00
|
|
|
type = T.nullOr T.str;
|
|
|
|
default = null;
|
2023-07-01 00:35:51 +02:00
|
|
|
description = lib.mdDoc ''
|
2023-06-12 23:21:24 +02:00
|
|
|
Default for new events or if khal does not understand the timezone
|
|
|
|
in an ical file.
|
2023-07-01 00:35:51 +02:00
|
|
|
If `null`, the timezone of your computer will be used.
|
2023-06-12 23:21:24 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2023-07-01 00:35:51 +02:00
|
|
|
local_timezone = mkOption {
|
2023-06-12 23:21:24 +02:00
|
|
|
type = T.nullOr T.str;
|
|
|
|
default = null;
|
2023-07-01 00:35:51 +02:00
|
|
|
description = lib.mdDoc ''
|
2023-06-12 23:21:24 +02:00
|
|
|
khal will show all times in this timezone.
|
2023-07-01 00:35:51 +02:00
|
|
|
If `null`, the timezone of your computer will be used.
|
2023-06-12 23:21:24 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2023-07-01 00:35:51 +02:00
|
|
|
firstweekday = mkOption {
|
2023-06-12 23:21:24 +02:00
|
|
|
type = T.ints.between 0 6;
|
|
|
|
default = 0;
|
2023-07-01 00:35:51 +02:00
|
|
|
description = lib.mdDoc ''
|
|
|
|
The first day of the week, where Monday is 0 and Sunday is 6.
|
2023-06-12 23:21:24 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2023-07-01 00:35:51 +02:00
|
|
|
weeknumbers = mkOption {
|
2023-06-12 23:21:24 +02:00
|
|
|
type = T.enum [ "off" "left" "right" ];
|
|
|
|
default = "off";
|
2023-07-01 00:35:51 +02:00
|
|
|
description = lib.mdDoc ''
|
|
|
|
Enable week numbers in calendar and interactive (ikhal) mode.
|
|
|
|
As those are ISO week numbers, they only work properly if
|
|
|
|
{option}`firstweekday` is set to 0.
|
2023-06-12 23:21:24 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
in {
|
|
|
|
options.programs.khal = {
|
2023-07-01 00:35:51 +02:00
|
|
|
enable = mkEnableOption (lib.mdDoc "khal, a CLI calendar application");
|
2023-06-12 23:21:24 +02:00
|
|
|
locale = mkOption {
|
2023-07-01 00:35:51 +02:00
|
|
|
type = lib.types.submodule { options = localeOptions; };
|
|
|
|
description = lib.mdDoc ''
|
2023-06-12 23:21:24 +02:00
|
|
|
khal locale settings.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
home.packages = [ pkgs.khal ];
|
|
|
|
|
|
|
|
xdg.configFile."khal/config".text = concatStringsSep "\n" ([ "[calendars]" ]
|
|
|
|
++ mapAttrsToList genCalendarStr khalAccounts ++ [
|
|
|
|
(generators.toINI { } {
|
|
|
|
# locale = definedAttrs (cfg.locale // { _module = null; });
|
|
|
|
|
|
|
|
default = optionalAttrs (!isNull primaryAccount) {
|
2023-07-04 12:14:47 +02:00
|
|
|
highlight_event_days = true;
|
2023-06-12 23:21:24 +02:00
|
|
|
default_calendar = if isNull primaryAccount.primaryCollection then
|
|
|
|
primaryAccount.name
|
|
|
|
else
|
|
|
|
primaryAccount.primaryCollection;
|
|
|
|
};
|
|
|
|
})
|
|
|
|
]);
|
|
|
|
};
|
|
|
|
}
|