1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2024-12-15 17:50:53 +00:00
home-manager/modules/programs/khal.nix
Matthieu Coudron b01eb1eb3b
Add infrastructure for contacts and calendars (#4078)
* Add infrastructure for contacts and calendars

This also adds the modules

  - programs.vdirsyncer,
  - programs.khal, and
  - services.vdirsyncer

that integrate with the new infrastructure.

Co-authored-by: Andrew Scott <3648487+ayyjayess@users.noreply.github.com>
Co-authored-by: Sebastian Zivota <sebastian.zivota@mailbox.org>

wip

* vdirsyncer: allow option userName, disallow userNameCommand

1. account option `userName` is now allowed by `programs.vdirsyncer`

2. The commented out account option `userNameCommand` was required to be set
   by `programs.vdirsyncer` (e.g. as `null`).
   It is now disallowed (commented out) by vdirsyncer.

* khal: added options 'color' and 'priority'
* Apply nixfmt

---------

Co-authored-by: Sebastian Zivota <sebastian.zivota@mailbox.org>
Co-authored-by: Johannes Rosenberger <johannes.rosenberger@jorsn.eu>
Co-authored-by: Johannes Rosenberger <johannes@jorsn.eu>
Co-authored-by: Robert Helgesson <robert@rycee.net>
2023-06-12 23:21:24 +02:00

170 lines
4.6 KiB
Nix
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 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}]]"
"highlight_event_days = True"
"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;
in mapAttrs (n: v:
v // {
description = v.description + ''
Format strings are for python 'strftime', similarly to man 3 strftime.
'';
}) {
dateformat = {
type = T.str;
default = "%x";
description = ''
khal will display and understand all dates in this format.
'';
};
timeformat = {
type = T.str;
default = "%X";
description = ''
khal will display and understand all times in this format.
'';
};
datetimeformat = {
type = T.str;
default = "%c";
description = ''
khal will display and understand all datetimes in this format.
'';
};
longdateformat = {
type = T.str;
default = "%x";
description = ''
khal will display and understand all dates in this format.
It should contain a year (e.g. %Y).
'';
};
longdatetimeformat = {
type = T.str;
default = "%c";
description = ''
khal will display and understand all datetimes in this format.
It should contain a year (e.g. %Y).
'';
};
};
localeOptions = let T = lib.types;
in localeFormatOptions // {
unicode_symbols = {
type = T.bool;
default = true;
description = ''
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 = {
type = T.nullOr T.str;
default = null;
description = ''
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 = {
type = T.nullOr T.str;
default = null;
description = ''
khal will show all times in this timezone.
If 'null', the timezone of your computer will be used.
'';
};
firstweekday = {
type = T.ints.between 0 6;
default = 0;
description = ''
the first day of the week, where Monday is 0 and Sunday is 6
'';
};
weeknumbers = {
type = T.enum [ "off" "left" "right" ];
default = "off";
description = ''
Enable weeknumbers in calendar and interactive (ikhal) mode.
As those are iso weeknumbers, they only work properly if firstweekday
is set to 0.
'';
};
};
in {
options.programs.khal = {
enable = mkEnableOption "khal, a CLI calendar application";
locale = mkOption {
type = lib.types.submodule {
options = mapAttrs (n: v: mkOption v) localeOptions;
};
description = ''
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) {
default_calendar = if isNull primaryAccount.primaryCollection then
primaryAccount.name
else
primaryAccount.primaryCollection;
};
})
]);
};
}