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