From c3abf8ea1adf8f601e993de64921bcf4f52b6358 Mon Sep 17 00:00:00 2001 From: Anton Mosich Date: Sun, 14 Sep 2025 00:31:16 +0000 Subject: [PATCH] khard: support discover entries (#7785) This adds support for discover type entries, which were introduced in khard 0.20.0, which work very similar to the equally-named khal feature. --- modules/programs/khard.nix | 31 ++++++++++++++++++- tests/modules/programs/khard/default.nix | 1 + .../modules/programs/khard/discover_type.nix | 20 ++++++++++++ .../programs/khard/discover_type_expected | 9 ++++++ 4 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 tests/modules/programs/khard/discover_type.nix create mode 100644 tests/modules/programs/khard/discover_type_expected diff --git a/modules/programs/khard.nix b/modules/programs/khard.nix index 80e22475..f5fb35d4 100644 --- a/modules/programs/khard.nix +++ b/modules/programs/khard.nix @@ -107,6 +107,26 @@ in default value will set the aforementioned path as a single vdir. ''; }; + options.khard.type = lib.mkOption { + type = types.enum [ + "vdir" + "discover" + ]; + default = "vdir"; + description = '' + Either a single vdir located in [](#opt-accounts.contact.accounts._name_.local.path) + or multiple automatically discovered vdirs in + [](#opt-accounts.contact.accounts._name_.local.path)/[](#opt-accounts.contact.accounts._name_.khard.glob). + ''; + }; + options.khard.glob = lib.mkOption { + type = lib.types.str; + default = "*"; + description = '' + The glob expansion to be searched for contacts when + type is set to discover. + ''; + }; } ); }; @@ -131,11 +151,20 @@ in [[${makeName anAccount.name anAbook}]] path = ${makePath anAccount.local.path anAbook} ''; + makeDiscoverEntry = anAccount: '' + [[${makeName anAccount.name ""}]] + path = ${anAccount.local.path}/${anAccount.khard.glob} + type = discover + ''; in '' [addressbooks] ${lib.concatMapStringsSep "\n" ( - acc: lib.concatMapStringsSep "\n" (makeEntry acc) acc.khard.addressbooks + acc: + if acc.khard.type == "discover" then + makeDiscoverEntry acc + else + lib.concatMapStringsSep "\n" (makeEntry acc) acc.khard.addressbooks ) (lib.attrValues accounts)} ${renderSettings cfg.settings} diff --git a/tests/modules/programs/khard/default.nix b/tests/modules/programs/khard/default.nix index e50d28ba..8b25efe8 100644 --- a/tests/modules/programs/khard/default.nix +++ b/tests/modules/programs/khard/default.nix @@ -4,4 +4,5 @@ khard_multiple_accounts = ./multiple_accounts.nix; khard_dirty_path = ./dirty_path.nix; khard_multiple_with_abooks = ./multiple_with_abooks.nix; + khard_discover_type = ./discover_type.nix; } diff --git a/tests/modules/programs/khard/discover_type.nix b/tests/modules/programs/khard/discover_type.nix new file mode 100644 index 00000000..1d4e1768 --- /dev/null +++ b/tests/modules/programs/khard/discover_type.nix @@ -0,0 +1,20 @@ +{ + accounts.contact = { + basePath = ".contacts"; + accounts.test = { + local.type = "filesystem"; + khard = { + enable = true; + type = "discover"; + }; + }; + }; + + programs.khard.enable = true; + + nmt.script = '' + assertFileContent \ + home-files/.config/khard/khard.conf \ + ${./discover_type_expected} + ''; +} diff --git a/tests/modules/programs/khard/discover_type_expected b/tests/modules/programs/khard/discover_type_expected new file mode 100644 index 00000000..fcb5fb7a --- /dev/null +++ b/tests/modules/programs/khard/discover_type_expected @@ -0,0 +1,9 @@ +[addressbooks] +[[test]] +path = /home/hm-user/.contacts/test/* +type = discover + + +[general] +default_action=list +