mirror of
https://github.com/nix-community/home-manager
synced 2024-11-22 20:53:14 +00:00
khard: add module
This commit is contained in:
parent
209a24dff2
commit
6f9b5b83ad
11 changed files with 212 additions and 0 deletions
|
@ -1251,6 +1251,13 @@ in
|
||||||
A new module is available: 'programs.wpaperd'.
|
A new module is available: 'programs.wpaperd'.
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
time = "2023-10-01T07:28:45+00:00";
|
||||||
|
message = ''
|
||||||
|
A new module is available: 'programs.khard'.
|
||||||
|
'';
|
||||||
|
}
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -121,6 +121,7 @@ let
|
||||||
./programs/kakoune.nix
|
./programs/kakoune.nix
|
||||||
./programs/keychain.nix
|
./programs/keychain.nix
|
||||||
./programs/khal.nix
|
./programs/khal.nix
|
||||||
|
./programs/khard.nix
|
||||||
./programs/kitty.nix
|
./programs/kitty.nix
|
||||||
./programs/kodi.nix
|
./programs/kodi.nix
|
||||||
./programs/lazygit.nix
|
./programs/lazygit.nix
|
||||||
|
|
88
modules/programs/khard.nix
Normal file
88
modules/programs/khard.nix
Normal 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}
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
}
|
|
@ -93,6 +93,7 @@ import nmt {
|
||||||
./modules/programs/k9s
|
./modules/programs/k9s
|
||||||
./modules/programs/kakoune
|
./modules/programs/kakoune
|
||||||
./modules/programs/khal
|
./modules/programs/khal
|
||||||
|
./modules/programs/khard
|
||||||
./modules/programs/kitty
|
./modules/programs/kitty
|
||||||
./modules/programs/ledger
|
./modules/programs/ledger
|
||||||
./modules/programs/less
|
./modules/programs/less
|
||||||
|
|
34
tests/modules/programs/khard/basic_config.nix
Normal file
34
tests/modules/programs/khard/basic_config.nix
Normal 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}
|
||||||
|
'';
|
||||||
|
}
|
15
tests/modules/programs/khard/basic_config_expected
Normal file
15
tests/modules/programs/khard/basic_config_expected
Normal 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
|
||||||
|
|
5
tests/modules/programs/khard/default.nix
Normal file
5
tests/modules/programs/khard/default.nix
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
khard_empty_config = ./empty_config.nix;
|
||||||
|
khard_basic_config = ./basic_config.nix;
|
||||||
|
khard_multiple_accounts = ./multiple_accounts.nix;
|
||||||
|
}
|
19
tests/modules/programs/khard/empty_config.nix
Normal file
19
tests/modules/programs/khard/empty_config.nix
Normal 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}
|
||||||
|
'';
|
||||||
|
}
|
8
tests/modules/programs/khard/empty_config_expected
Normal file
8
tests/modules/programs/khard/empty_config_expected
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
[addressbooks]
|
||||||
|
[[test]]
|
||||||
|
path = /home/hm-user/.contacts/test
|
||||||
|
|
||||||
|
|
||||||
|
[general]
|
||||||
|
default_action=list
|
||||||
|
|
23
tests/modules/programs/khard/multiple_accounts.nix
Normal file
23
tests/modules/programs/khard/multiple_accounts.nix
Normal 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}
|
||||||
|
'';
|
||||||
|
}
|
11
tests/modules/programs/khard/multiple_accounts_expected
Normal file
11
tests/modules/programs/khard/multiple_accounts_expected
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
[addressbooks]
|
||||||
|
[[test1]]
|
||||||
|
path = /home/hm-user/.contacts/test1
|
||||||
|
|
||||||
|
[[test2]]
|
||||||
|
path = /home/hm-user/.contacts/test2
|
||||||
|
|
||||||
|
|
||||||
|
[general]
|
||||||
|
default_action=list
|
||||||
|
|
Loading…
Reference in a new issue