fork/home-manager

git clone https://git.julia.blue/fork/home-manager

Olmo Kramerkhard: add module6f9b5b83

master
2.3 KiB88 linesraw
1{ config, lib, pkgs, ... }:
2let
3  cfg = config.programs.khard;
4
5  accounts =
6    lib.filterAttrs (_: acc: acc.khard.enable) config.accounts.contact.accounts;
7
8  renderSettings = with lib.generators;
9    toINI {
10      mkKeyValue = mkKeyValueDefault rec {
11        mkValueString = v:
12          if lib.isList v then
13            lib.concatStringsSep ", " v
14          else if lib.isBool v then
15            if v then "yes" else "no"
16          else
17            v;
18      } "=";
19    };
20in {
21  meta.maintainers =
22    [ lib.hm.maintainers.olmokramer lib.maintainers.antonmosich ];
23
24  options = {
25    programs.khard = {
26      enable = lib.mkEnableOption "Khard: an address book for the Unix console";
27
28      settings = lib.mkOption {
29        type = with lib.types;
30          submodule {
31            freeformType = let primOrList = oneOf [ bool str (listOf str) ];
32            in attrsOf (attrsOf primOrList);
33
34            options.general.default_action = lib.mkOption {
35              type = str;
36              default = "list";
37              description = "The default action to execute.";
38            };
39          };
40        default = { };
41        description = ''
42          Khard settings. See
43          <https://khard.readthedocs.io/en/latest/#configuration>
44          for more information.
45        '';
46        example = lib.literalExpression ''
47          {
48            general = {
49              default_action = "list";
50              editor = ["vim" "-i" "NONE"];
51            };
52
53            "contact table" = {
54              display = "formatted_name";
55              preferred_phone_number_type = ["pref" "cell" "home"];
56              preferred_email_address_type = ["pref" "work" "home"];
57            };
58
59            vcard = {
60              private_objects = ["Jabber" "Skype" "Twitter"];
61            };
62          }
63        '';
64      };
65    };
66
67    accounts.contact.accounts = lib.mkOption {
68      type = with lib.types;
69        attrsOf (submodule {
70          options.khard.enable = lib.mkEnableOption "khard access";
71        });
72    };
73  };
74
75  config = lib.mkIf cfg.enable {
76    home.packages = [ pkgs.khard ];
77
78    xdg.configFile."khard/khard.conf".text = ''
79      [addressbooks]
80      ${lib.concatMapStringsSep "\n" (acc: ''
81        [[${acc.name}]]
82        path = ${acc.local.path}
83      '') (lib.attrValues accounts)}
84
85      ${renderSettings cfg.settings}
86    '';
87  };
88}