fork/home-manager

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

Anton Mosichqcal: add module8eb8c212

master
1.7 KiB66 linesraw
1{ config, lib, pkgs, ... }:
2
3let
4
5  cfg = config.programs.qcal;
6
7  qcalAccounts = lib.attrValues
8    (lib.filterAttrs (_: a: a.qcal.enable) config.accounts.calendar.accounts);
9
10  rename = oldname:
11    builtins.getAttr oldname {
12      url = "Url";
13      userName = "Username";
14      passwordCommand = "PasswordCmd";
15    };
16
17  filteredAccounts = let
18    mkAccount = account:
19      lib.filterAttrs (_: v: v != null) (with account.remote; {
20        Url = url;
21        Username = if userName == null then null else userName;
22        PasswordCmd =
23          if passwordCommand == null then null else toString passwordCommand;
24      });
25  in map mkAccount qcalAccounts;
26
27in {
28  meta.maintainers = with lib.maintainers; [ antonmosich ];
29
30  options = {
31    programs.qcal = {
32      enable = lib.mkEnableOption "qcal, a CLI calendar application";
33
34      timezone = lib.mkOption {
35        type = lib.types.singleLineStr;
36        default = "Local";
37        example = "Europe/Vienna";
38        description = "Timezone to display calendar entries in";
39      };
40
41      defaultNumDays = lib.mkOption {
42        type = lib.types.ints.positive;
43        default = 30;
44        description = "Default number of days to show calendar entries for";
45      };
46    };
47
48    accounts.calendar.accounts = lib.mkOption {
49      type = with lib.types;
50        attrsOf
51        (submodule { options.qcal.enable = lib.mkEnableOption "qcal access"; });
52    };
53  };
54
55  config = lib.mkIf cfg.enable {
56    home.packages = [ pkgs.qcal ];
57
58    xdg.configFile."qcal/config.json".source =
59      let jsonFormat = pkgs.formats.json { };
60      in jsonFormat.generate "qcal.json" {
61        DefaultNumDays = cfg.defaultNumDays;
62        Timezone = cfg.timezone;
63        Calendars = filteredAccounts;
64      };
65  };
66}