khard: add module

This commit is contained in:
Olmo Kramer 2023-07-03 22:06:38 +02:00 committed by Robert Helgesson
parent 209a24dff2
commit 6f9b5b83ad
No known key found for this signature in database
GPG Key ID: 36BDAA14C2797E89
11 changed files with 212 additions and 0 deletions

View File

@ -1251,6 +1251,13 @@ in
A new module is available: 'programs.wpaperd'.
'';
}
{
time = "2023-10-01T07:28:45+00:00";
message = ''
A new module is available: 'programs.khard'.
'';
}
];
};
}

View File

@ -121,6 +121,7 @@ let
./programs/kakoune.nix
./programs/keychain.nix
./programs/khal.nix
./programs/khard.nix
./programs/kitty.nix
./programs/kodi.nix
./programs/lazygit.nix

View File

@ -0,0 +1,88 @@
{ config, lib, pkgs, ... }:
let
cfg = config.programs.khard;
accounts =
lib.filterAttrs (_: acc: acc.khard.enable) config.accounts.contact.accounts;
renderSettings = with lib.generators;
toINI {
mkKeyValue = mkKeyValueDefault rec {
mkValueString = v:
if lib.isList v then
lib.concatStringsSep ", " v
else if lib.isBool v then
if v then "yes" else "no"
else
v;
} "=";
};
in {
meta.maintainers =
[ lib.hm.maintainers.olmokramer lib.maintainers.antonmosich ];
options = {
programs.khard = {
enable = lib.mkEnableOption "Khard: an address book for the Unix console";
settings = lib.mkOption {
type = with lib.types;
submodule {
freeformType = let primOrList = oneOf [ bool str (listOf str) ];
in attrsOf (attrsOf primOrList);
options.general.default_action = lib.mkOption {
type = str;
default = "list";
description = "The default action to execute.";
};
};
default = { };
description = ''
Khard settings. See
<https://khard.readthedocs.io/en/latest/#configuration>
for more information.
'';
example = lib.literalExpression ''
{
general = {
default_action = "list";
editor = ["vim" "-i" "NONE"];
};
"contact table" = {
display = "formatted_name";
preferred_phone_number_type = ["pref" "cell" "home"];
preferred_email_address_type = ["pref" "work" "home"];
};
vcard = {
private_objects = ["Jabber" "Skype" "Twitter"];
};
}
'';
};
};
accounts.contact.accounts = lib.mkOption {
type = with lib.types;
attrsOf (submodule {
options.khard.enable = lib.mkEnableOption "khard access";
});
};
};
config = lib.mkIf cfg.enable {
home.packages = [ pkgs.khard ];
xdg.configFile."khard/khard.conf".text = ''
[addressbooks]
${lib.concatMapStringsSep "\n" (acc: ''
[[${acc.name}]]
path = ${acc.local.path}
'') (lib.attrValues accounts)}
${renderSettings cfg.settings}
'';
};
}

View File

@ -93,6 +93,7 @@ import nmt {
./modules/programs/k9s
./modules/programs/kakoune
./modules/programs/khal
./modules/programs/khard
./modules/programs/kitty
./modules/programs/ledger
./modules/programs/less

View File

@ -0,0 +1,34 @@
{
accounts.contact = {
basePath = ".contacts";
accounts.test = {
local.type = "filesystem";
khard.enable = true;
};
};
programs.khard = {
enable = true;
settings = {
general = {
default_action = "list";
editor = [ "vim" "-i" "NONE" ];
};
"contact table" = {
group_by_address_book = true;
reverse = false;
preferred_phone_number_type = [ "pref" "cell" "home" ];
preferred_email_address_type = [ "pref" "work" "home" ];
};
};
};
test.stubs.khard = { };
nmt.script = ''
assertFileContent \
home-files/.config/khard/khard.conf \
${./basic_config_expected}
'';
}

View File

@ -0,0 +1,15 @@
[addressbooks]
[[test]]
path = /home/hm-user/.contacts/test
[contact table]
group_by_address_book=yes
preferred_email_address_type=pref, work, home
preferred_phone_number_type=pref, cell, home
reverse=no
[general]
default_action=list
editor=vim, -i, NONE

View File

@ -0,0 +1,5 @@
{
khard_empty_config = ./empty_config.nix;
khard_basic_config = ./basic_config.nix;
khard_multiple_accounts = ./multiple_accounts.nix;
}

View File

@ -0,0 +1,19 @@
{
accounts.contact = {
basePath = ".contacts";
accounts.test = {
local.type = "filesystem";
khard.enable = true;
};
};
programs.khard.enable = true;
test.stubs.khard = { };
nmt.script = ''
assertFileContent \
home-files/.config/khard/khard.conf \
${./empty_config_expected}
'';
}

View File

@ -0,0 +1,8 @@
[addressbooks]
[[test]]
path = /home/hm-user/.contacts/test
[general]
default_action=list

View File

@ -0,0 +1,23 @@
{
accounts.contact = {
basePath = ".contacts";
accounts.test1 = {
local.type = "filesystem";
khard.enable = true;
};
accounts.test2 = {
local.type = "filesystem";
khard.enable = true;
};
};
programs.khard.enable = true;
test.stubs.khard = { };
nmt.script = ''
assertFileContent \
home-files/.config/khard/khard.conf \
${./multiple_accounts_expected}
'';
}

View File

@ -0,0 +1,11 @@
[addressbooks]
[[test1]]
path = /home/hm-user/.contacts/test1
[[test2]]
path = /home/hm-user/.contacts/test2
[general]
default_action=list