mirror of
https://github.com/nix-community/home-manager.git
synced 2025-11-08 19:46:05 +01:00
khard: add option to set mutiple subdirs (#6823)
Add new option `accounts.contact.accounts.<name>.khard.addressbooks`. Remove the previous soln, `accounts.contact.accounts.<name>.khard.defaultCollection`, which is superseded with the new option. Add a new test to check the new `addressbooks` option. Modify an existing test which was checking the removed `defaultCollection`. Previous commit a38f88 allowed a hardcoded path to be set for khard if the path set for its local storage is not the actual `vdir`. This was accomplished via adding the `defaultCollection` option. However this accepted only a single sub-directory, and when one has more than a single collection on the same dir this would require repetition on configuration to set [1]. This is a continuation of the soln given to nix-community/home-manager#4531, refer to there and the previous PR [2] for reference. [1]: https://github.com/nix-community/home-manager/issues/4531#issuecomment-2701156246 [2]: https://github.com/nix-community/home-manager/pull/5220
This commit is contained in:
parent
72526a5f7c
commit
5e6a8203ce
6 changed files with 84 additions and 19 deletions
|
|
@ -5,6 +5,8 @@
|
|||
...
|
||||
}:
|
||||
let
|
||||
inherit (lib) types;
|
||||
|
||||
cfg = config.programs.khard;
|
||||
|
||||
accounts = lib.filterAttrs (_: acc: acc.khard.enable) config.accounts.contact.accounts;
|
||||
|
|
@ -25,6 +27,7 @@ let
|
|||
};
|
||||
in
|
||||
{
|
||||
|
||||
meta.maintainers = [
|
||||
lib.hm.maintainers.olmokramer
|
||||
lib.maintainers.antonmosich
|
||||
|
|
@ -84,16 +87,28 @@ in
|
|||
};
|
||||
|
||||
accounts.contact.accounts = lib.mkOption {
|
||||
type =
|
||||
with lib.types;
|
||||
attrsOf (submodule {
|
||||
type = types.attrsOf (
|
||||
types.submodule {
|
||||
imports = [
|
||||
(lib.mkRenamedOptionModule [ "khard" "defaultCollection" ] [ "khard" "addressbooks" ])
|
||||
];
|
||||
options.khard.enable = lib.mkEnableOption "khard access";
|
||||
options.khard.defaultCollection = lib.mkOption {
|
||||
type = types.str;
|
||||
default = "";
|
||||
description = "VCARD collection to be searched by khard.";
|
||||
options.khard.addressbooks = lib.mkOption {
|
||||
type = types.coercedTo types.str lib.toList (types.listOf types.str);
|
||||
default = [ "" ];
|
||||
description = ''
|
||||
If provided, each item on this list will generate an
|
||||
entry on khard configuration file as a separate addressbook
|
||||
(vdir).
|
||||
|
||||
This is used for hardcoding sub-directories under the local
|
||||
storage path
|
||||
(accounts.contact.accounts.<name>.local.path) for khard. The
|
||||
default value will set the aforementioned path as a single vdir.
|
||||
'';
|
||||
};
|
||||
});
|
||||
}
|
||||
);
|
||||
};
|
||||
};
|
||||
|
||||
|
|
@ -103,21 +118,25 @@ in
|
|||
xdg.configFile."khard/khard.conf".text =
|
||||
let
|
||||
makePath =
|
||||
anAccount:
|
||||
baseDir: subDir:
|
||||
builtins.toString (
|
||||
/.
|
||||
+ lib.concatStringsSep "/" [
|
||||
anAccount.local.path
|
||||
anAccount.khard.defaultCollection
|
||||
baseDir
|
||||
subDir
|
||||
]
|
||||
);
|
||||
makeName = accName: abookName: accName + lib.optionalString (abookName != "") "-${abookName}";
|
||||
makeEntry = anAccount: anAbook: ''
|
||||
[[${makeName anAccount.name anAbook}]]
|
||||
path = ${makePath anAccount.local.path anAbook}
|
||||
'';
|
||||
in
|
||||
''
|
||||
[addressbooks]
|
||||
${lib.concatMapStringsSep "\n" (acc: ''
|
||||
[[${acc.name}]]
|
||||
path = ${makePath acc}
|
||||
'') (lib.attrValues accounts)}
|
||||
${lib.concatMapStringsSep "\n" (
|
||||
acc: lib.concatMapStringsSep "\n" (makeEntry acc) acc.khard.addressbooks
|
||||
) (lib.attrValues accounts)}
|
||||
|
||||
${renderSettings cfg.settings}
|
||||
'';
|
||||
|
|
|
|||
|
|
@ -3,4 +3,5 @@
|
|||
khard_basic_config = ./basic_config.nix;
|
||||
khard_multiple_accounts = ./multiple_accounts.nix;
|
||||
khard_dirty_path = ./dirty_path.nix;
|
||||
khard_multiple_with_abooks = ./multiple_with_abooks.nix;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
{
|
||||
accounts.contact = {
|
||||
basePath = "/home/user/who/likes///";
|
||||
accounts.forward = {
|
||||
accounts.kebap-case = {
|
||||
local.type = "filesystem";
|
||||
khard = {
|
||||
enable = true;
|
||||
defaultCollection = "////slashes//a/lot";
|
||||
addressbooks = [ "named-abook" ];
|
||||
};
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
[addressbooks]
|
||||
[[forward]]
|
||||
path = /home/user/who/likes/forward/slashes/a/lot
|
||||
[[kebap-case-named-abook]]
|
||||
path = /home/user/who/likes/kebap-case/named-abook
|
||||
|
||||
|
||||
[general]
|
||||
|
|
|
|||
28
tests/modules/programs/khard/multiple_with_abooks.nix
Normal file
28
tests/modules/programs/khard/multiple_with_abooks.nix
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
{
|
||||
accounts.contact = {
|
||||
basePath = ".contacts";
|
||||
accounts.test1 = {
|
||||
local.type = "filesystem";
|
||||
khard = {
|
||||
enable = true;
|
||||
addressbooks = [
|
||||
"home"
|
||||
"work"
|
||||
"family"
|
||||
];
|
||||
};
|
||||
};
|
||||
accounts.test2 = {
|
||||
local.type = "filesystem";
|
||||
khard.enable = true;
|
||||
};
|
||||
};
|
||||
|
||||
programs.khard.enable = true;
|
||||
|
||||
nmt.script = ''
|
||||
assertFileContent \
|
||||
home-files/.config/khard/khard.conf \
|
||||
${./multiple_with_abooks_expected}
|
||||
'';
|
||||
}
|
||||
17
tests/modules/programs/khard/multiple_with_abooks_expected
Normal file
17
tests/modules/programs/khard/multiple_with_abooks_expected
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
[addressbooks]
|
||||
[[test1-home]]
|
||||
path = /home/hm-user/.contacts/test1/home
|
||||
|
||||
[[test1-work]]
|
||||
path = /home/hm-user/.contacts/test1/work
|
||||
|
||||
[[test1-family]]
|
||||
path = /home/hm-user/.contacts/test1/family
|
||||
|
||||
[[test2]]
|
||||
path = /home/hm-user/.contacts/test2
|
||||
|
||||
|
||||
[general]
|
||||
default_action=list
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue