fork/home-manager

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

Robert HelgessonMerge PR #421575790441

master
2.5 KiB94 linesraw
1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6
7  cfg = config.programs.watson;
8
9  iniFormat = pkgs.formats.ini { };
10
11  configDir = if pkgs.stdenv.hostPlatform.isDarwin then
12    "Library/Application Support"
13  else
14    config.xdg.configHome;
15
16in {
17  meta.maintainers = [ maintainers.polykernel ];
18
19  options.programs.watson = {
20    enable = mkEnableOption "watson, a wonderful CLI to track your time";
21
22    package = mkOption {
23      type = types.package;
24      default = pkgs.watson;
25      defaultText = literalExpression "pkgs.watson";
26      description = "Package providing the {command}`watson`.";
27    };
28
29    enableBashIntegration = mkEnableOption "watson's bash integration" // {
30      default = true;
31    };
32
33    enableZshIntegration = mkEnableOption "watson's zsh integration" // {
34      default = true;
35    };
36
37    enableFishIntegration = mkEnableOption "watson's fish integration" // {
38      default = true;
39    };
40
41    settings = mkOption {
42      type = iniFormat.type;
43      default = { };
44      description = ''
45        Configuration written to
46        {file}`$XDG_CONFIG_HOME/watson/config` on Linux or
47        {file}`$HOME/Library/Application Support/watson/config` on Darwin.
48
49        See <https://github.com/TailorDev/Watson/blob/master/docs/user-guide/configuration.md>
50        for an example configuration.
51      '';
52      example = literalExpression ''
53        {
54          backend = {
55            url = "https://api.crick.fr";
56            token = "yourapitoken";
57          };
58
59          options = {
60            stop_on_start = true;
61            stop_on_restart = false;
62            date_format = "%Y.%m.%d";
63            time_format = "%H:%M:%S%z";
64            week_start = "monday";
65            log_current = false;
66            pager = true;
67            report_current = false;
68            reverse_log = true;
69          };
70        }
71      '';
72    };
73  };
74
75  config = mkIf cfg.enable {
76    home.packages = [ cfg.package ];
77
78    home.file."${configDir}/watson/config" = mkIf (cfg.settings != { }) {
79      source = iniFormat.generate "watson-config" cfg.settings;
80    };
81
82    programs.bash.initExtra = mkIf cfg.enableBashIntegration ''
83      source ${cfg.package}/share/bash-completion/completions/watson
84    '';
85
86    programs.zsh.initExtra = mkIf cfg.enableZshIntegration ''
87      source ${cfg.package}/share/zsh/site-functions/_watson
88    '';
89
90    programs.fish.shellInit = mkIf cfg.enableFishIntegration ''
91      source ${cfg.package}/share/fish/vendor_completions.d/watson.fish
92    '';
93  };
94}