1
0
mirror of https://github.com/nix-community/home-manager synced 2024-06-01 04:23:34 +02:00
home-manager/modules/programs/khal.nix
Emily 3228f92b90 treewide: manually convert some docs to Markdown
These files all have options that trip up the `nix-doc-munge`
conversion tool for one reason or another (syntax that clashes with
Markdown, options that were already using Markdown syntax despite not
being marked that way, output that differs slightly after conversion,
syntax too elaborate to convert with some cheap regular expressions,
...). Translate them manually and do a little copyediting to options
in the vicinity while we're at it.
2023-07-17 16:49:35 +01:00

177 lines
4.7 KiB
Nix

# 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" ]);
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}
'';
};
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}
'';
};
};
localeOptions = let T = lib.types;
in localeFormatOptions // {
unicode_symbols = mkOption {
type = T.bool;
default = true;
description = lib.mdDoc ''
By default khal uses some Unicode symbols (as in "non-ASCII") as
indicators for things like repeating events.
If your font, encoding etc. does not support those symbols, set this
to false (this will enable ASCII-based replacements).
'';
};
default_timezone = mkOption {
type = T.nullOr T.str;
default = null;
description = lib.mdDoc ''
Default for new events or if khal does not understand the timezone
in an ical file.
If `null`, the timezone of your computer will be used.
'';
};
local_timezone = mkOption {
type = T.nullOr T.str;
default = null;
description = lib.mdDoc ''
khal will show all times in this timezone.
If `null`, the timezone of your computer will be used.
'';
};
firstweekday = mkOption {
type = T.ints.between 0 6;
default = 0;
description = lib.mdDoc ''
The first day of the week, where Monday is 0 and Sunday is 6.
'';
};
weeknumbers = mkOption {
type = T.enum [ "off" "left" "right" ];
default = "off";
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.
'';
};
};
in {
options.programs.khal = {
enable = mkEnableOption (lib.mdDoc "khal, a CLI calendar application");
locale = mkOption {
type = lib.types.submodule { options = localeOptions; };
description = lib.mdDoc ''
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) {
highlight_event_days = true;
default_calendar = if isNull primaryAccount.primaryCollection then
primaryAccount.name
else
primaryAccount.primaryCollection;
};
})
]);
};
}