1
0
mirror of https://github.com/nix-community/home-manager synced 2024-06-01 04:23:34 +02:00

khal: fix contact integration (#4836)

* khal: fix contact integration

- Add tests for contact+khal
- Make options `color`/`priority` available for contact accounts

* khal: add separate calendar for each contact collection

A contact account may have multiple VCARD collections, but Khal doesn't
search recursively. Collection folder names must be hardcoded, and each
has its own calendar.

- Add khal.collections option for contact accounts
- Default to previous setup for accounts with a single collection
- Add tests

* khal: specify how priority is defined by Khal

See https://khal.readthedocs.io/en/latest/configure.html
This commit is contained in:
Felipe Silva 2024-03-03 14:12:42 -03:00 committed by Mikilio
parent 0e561e8755
commit 6c7547cbcb
No known key found for this signature in database
GPG Key ID: 5B2F1A890CF33F3F
7 changed files with 120 additions and 38 deletions

View File

@ -126,6 +126,7 @@ in {
contactOpts
(import ../programs/vdirsyncer-accounts.nix)
(import ../programs/khal-accounts.nix)
(import ../programs/khal-contact-accounts.nix)
]);
default = { };
description = "List of contacts.";

View File

@ -13,5 +13,39 @@ with lib;
Keep khal from making any changes to this account.
'';
};
color = mkOption {
type = types.nullOr (types.enum [
"black"
"white"
"brown"
"yellow"
"dark gray"
"dark green"
"dark blue"
"light gray"
"light green"
"light blue"
"dark magenta"
"dark cyan"
"dark red"
"light magenta"
"light cyan"
"light red"
]);
default = null;
description = ''
Color in which events in this calendar are displayed.
'';
example = "light green";
};
priority = mkOption {
type = types.int;
default = 10;
description = ''
Priority of a calendar used for coloring (calendar with highest priority is preferred).
'';
};
};
}

View File

@ -20,39 +20,5 @@ with lib;
type is set to discover.
'';
};
color = mkOption {
type = types.nullOr (types.enum [
"black"
"white"
"brown"
"yellow"
"dark gray"
"dark green"
"dark blue"
"light gray"
"light green"
"light blue"
"dark magenta"
"dark cyan"
"dark red"
"light magenta"
"light cyan"
"light red"
]);
default = null;
description = ''
Color in which events in this calendar are displayed.
'';
example = "light green";
};
priority = mkOption {
type = types.int;
default = 10;
description = ''
Priority of a calendar used for coloring.
'';
};
};
}

View File

@ -0,0 +1,15 @@
{ config, lib, ... }:
with lib;
{
options.khal = {
collections = mkOption {
type = types.nullOr (types.listOf types.str);
default = null;
description = ''
VCARD collections to be searched for contact birthdays.
'';
};
};
}

View File

@ -12,13 +12,25 @@ let
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);
# a contact account may have multiple collections, each a separate calendar
expandContactAccount = name: acct:
if acct.khal.collections != null then
listToAttrs (map (c: {
name = "${name}-${c}";
value = recursiveUpdate acct { khal.thisCollection = c; };
}) acct.khal.collections)
else {
${name} = acct;
};
khalContactAccounts = concatMapAttrs expandContactAccount
(mapAttrs (_: v: recursiveUpdate v { khal.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);
(mapAttrsToList (n: v: v // { name = n; }) khalCalendarAccounts);
definedAttrs = filterAttrs (_: v: !isNull v);
@ -30,6 +42,9 @@ let
"path = ${
value.local.path + "/"
+ (optionalString (value.khal.type == "discover") value.khal.glob)
+ (optionalString
(value.khal.type == "birthdays" && value.khal ? thisCollection)
value.khal.thisCollection)
}"
] ++ optional (value.khal.readOnly) "readonly = True" ++ [
(toKeyValueIfDefined (getAttrs [ "type" "color" "priority" ] value.khal))
@ -153,7 +168,7 @@ in {
locale = mkOption {
type = lib.types.submodule { options = localeOptions; };
description = ''
khal locale settings.
khal locale settings.
'';
default = { };
};

View File

@ -32,6 +32,36 @@
};
};
accounts.contact = {
basePath = "$XDG_CONFIG_HOME/card";
accounts = {
testcontacts = {
khal = {
enable = true;
collections = [ "default" "automaticallyCollected" ];
};
local.type = "filesystem";
local.fileExt = ".vcf";
name = "testcontacts";
remote = {
type = "http";
url = "https://example.com/contacts.vcf";
};
};
testcontactsNoCollections = {
khal.enable = true;
local.type = "filesystem";
local.fileExt = ".vcf";
name = "testcontactsNoCollections";
remote = {
type = "http";
url = "https://example.com/contacts.vcf";
};
};
};
};
test.stubs = { khal = { }; };
nmt.script = ''

View File

@ -7,6 +7,27 @@ type=calendar
[[testcontacts-automaticallyCollected]]
path = /home/hm-user/$XDG_CONFIG_HOME/card/testcontacts/automaticallyCollected
priority=10
type=birthdays
[[testcontacts-default]]
path = /home/hm-user/$XDG_CONFIG_HOME/card/testcontacts/default
priority=10
type=birthdays
[[testcontactsNoCollections]]
path = /home/hm-user/$XDG_CONFIG_HOME/card/testcontactsNoCollections/
priority=10
type=birthdays
[default]
default_calendar=test
highlight_event_days=true