fork/home-manager

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

Matthieu CoudronAdd infrastructure for contacts and calendars (#4078)b01eb1eb

master
3.3 KiB134 linesraw
1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6
7  cfg = config.accounts.contact;
8
9  localModule = name:
10    types.submodule {
11      options = {
12        path = mkOption {
13          type = types.str;
14          default = "${cfg.basePath}/${name}";
15          defaultText = "‹accounts.contact.basePath›/‹name›";
16          description = "The path of the storage.";
17        };
18
19        type = mkOption {
20          type = types.enum [ "filesystem" "singlefile" ];
21          description = "The type of the storage.";
22        };
23
24        fileExt = mkOption {
25          type = types.nullOr types.str;
26          default = null;
27          description = "The file extension to use.";
28        };
29
30        encoding = mkOption {
31          type = types.nullOr types.str;
32          default = null;
33          description = ''
34            File encoding for items, both content and file name.
35            Defaults to UTF-8.
36          '';
37        };
38      };
39    };
40
41  remoteModule = types.submodule {
42    options = {
43      type = mkOption {
44        type = types.enum [ "carddav" "http" "google_contacts" ];
45        description = "The type of the storage.";
46      };
47
48      url = mkOption {
49        type = types.nullOr types.str;
50        default = null;
51        description = "The URL of the storage.";
52      };
53
54      userName = mkOption {
55        type = types.nullOr types.str;
56        default = null;
57        description = "User name for authentication.";
58      };
59
60      # userNameCommand = mkOption {
61      #   type = types.nullOr (types.listOf types.str);
62      #   default = null;
63      #   example = [ "~/get-username.sh" ];
64      #   description = ''
65      #     A command that prints the user name to standard output.
66      #   '';
67      # };
68
69      passwordCommand = mkOption {
70        type = types.nullOr (types.listOf types.str);
71        default = null;
72        example = [ "pass" "caldav" ];
73        description = ''
74          A command that prints the password to standard output.
75        '';
76      };
77    };
78  };
79
80  contactOpts = { name, config, ... }: {
81    options = {
82      name = mkOption {
83        type = types.str;
84        readOnly = true;
85        description = ''
86          Unique identifier of the contact account. This is set to the
87          attribute name of the contact configuration.
88        '';
89      };
90
91      local = mkOption {
92        type = types.nullOr (localModule name);
93        default = null;
94        description = ''
95          Local configuration for the contacts.
96        '';
97      };
98
99      remote = mkOption {
100        type = types.nullOr remoteModule;
101        default = null;
102        description = ''
103          Remote configuration for the contacts.
104        '';
105      };
106    };
107
108    config = { name = name; };
109  };
110
111in {
112  options.accounts.contact = {
113    basePath = mkOption {
114      type = types.str;
115      apply = p:
116        if hasPrefix "/" p then p else "${config.home.homeDirectory}/${p}";
117      description = ''
118        The base directory in which to save contacts. May be a
119        relative path, in which case it is relative the home
120        directory.
121      '';
122    };
123
124    accounts = mkOption {
125      type = types.attrsOf (types.submodule [
126        contactOpts
127        (import ../programs/vdirsyncer-accounts.nix)
128        (import ../programs/khal-accounts.nix)
129      ]);
130      default = { };
131      description = "List of contacts.";
132    };
133  };
134}