yep, more dotfiles
1{ config
2, lib
3, pkgs
4, ...
5}:
6
7let
8 cfg = config.programs.wakatime;
9
10 ini-format = pkgs.formats.ini { };
11in
12{
13 options.programs.wakatime = with lib; {
14 enable = mkEnableOption "Wakatime code time tracker";
15
16 apiKeyFile = mkOption {
17 description = "Path to a file containing your api key";
18 type = types.nullOr types.str;
19 };
20
21 settings = mkOption {
22 description = ''
23 Wakatime CLI settings that impacts every extension
24
25 See options at <https://github.com/wakatime/wakatime-cli/blob/develop/USAGE.md#ini-config-file>
26 '';
27 default = { };
28 example = {
29 exclude = [
30 "^COMMIT_EDITMSG$"
31 "^TAG_EDITMSG$"
32 "^/var/(?!www/).*"
33 "^/etc/"
34 ];
35 include = [ ".*" ];
36 };
37 # We only want a single INI section type
38 type = ini-format.type.nestedTypes.elemType;
39 };
40
41 extraConfig = mkOption {
42 description = "Define additional wakatime configuration options";
43 default = { };
44 example = {
45 git = {
46 submodules_disabled = false;
47 project_from_git_remote = false;
48 };
49 };
50 type = ini-format.type;
51 };
52 };
53
54 config =
55 let
56 # Bash script is needed cause file path can contain env variables
57 # e.g. agenix uses `$XDG_RUNTIME_DIR`
58 wakatime-key = pkgs.writeShellScript "cat-wakatime-api-key" "cat ${cfg.apiKeyFile}";
59
60 merged-settings = cfg.settings // { api_key_vault_cmd = "${wakatime-key}"; };
61 final-config = cfg.extraConfig // { settings = merged-settings; };
62 in
63 lib.mkIf cfg.enable {
64 home.sessionVariables.WAKATIME_HOME = "${config.xdg.configHome}/wakatime";
65
66 xdg.configFile = {
67 "wakatime/.wakatime.cfg".source = ini-format.generate "wakatime-config" final-config;
68 };
69 };
70}
71