From d469b9bf8a1ca8b596eb86a25b478560fdf3cc2b Mon Sep 17 00:00:00 2001
From: polykernel <81340136+polykernel@users.noreply.github.com>
Date: Sat, 1 Jan 2022 18:22:05 -0500
Subject: [PATCH] watson: add module
Watson is a CLI for tracking your time.
Two unit tests were added to validate the module behavior for an empty
configuration and the example configuration.
---
.github/CODEOWNERS | 3 +
modules/misc/news.nix | 7 ++
modules/modules.nix | 1 +
modules/programs/watson.nix | 94 +++++++++++++++++++
tests/default.nix | 1 +
tests/modules/programs/watson/default.nix | 4 +
.../programs/watson/empty-settings.nix | 19 ++++
.../watson/example-settings-expected.ini | 14 +++
.../programs/watson/example-settings.nix | 40 ++++++++
9 files changed, 183 insertions(+)
create mode 100644 modules/programs/watson.nix
create mode 100644 tests/modules/programs/watson/default.nix
create mode 100644 tests/modules/programs/watson/empty-settings.nix
create mode 100644 tests/modules/programs/watson/example-settings-expected.ini
create mode 100644 tests/modules/programs/watson/example-settings.nix
diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS
index e8ea4317..7aedc793 100644
--- a/.github/CODEOWNERS
+++ b/.github/CODEOWNERS
@@ -224,6 +224,9 @@
/modules/programs/topgrade.nix @msfjarvis
/tests/modules/programs/topgrade @msfjarvis
+/mdules/programs/watson.nix @polykernel
+/tests/modules/programs/watson @polykernel
+
/modules/programs/waybar.nix @berbiche
/tests/modules/programs/waybar @berbiche
diff --git a/modules/misc/news.nix b/modules/misc/news.nix
index 2fb665fe..5840a274 100644
--- a/modules/misc/news.nix
+++ b/modules/misc/news.nix
@@ -2358,6 +2358,13 @@ in
A new module is available: 'programs.helix'.
'';
}
+
+ {
+ time = "2022-01-22T15:12:20+00:00";
+ message = ''
+ A new module is available: 'programs.watson'.
+ '';
+ }
];
};
}
diff --git a/modules/modules.nix b/modules/modules.nix
index 3cd72e2b..3b6fda0f 100644
--- a/modules/modules.nix
+++ b/modules/modules.nix
@@ -148,6 +148,7 @@ let
./programs/vim.nix
./programs/vscode.nix
./programs/vscode/haskell.nix
+ ./programs/watson.nix
./programs/waybar.nix
./programs/xmobar.nix
./programs/z-lua.nix
diff --git a/modules/programs/watson.nix b/modules/programs/watson.nix
new file mode 100644
index 00000000..54cfbc13
--- /dev/null
+++ b/modules/programs/watson.nix
@@ -0,0 +1,94 @@
+{ config, lib, pkgs, ... }:
+
+with lib;
+
+let
+
+ cfg = config.programs.watson;
+
+ iniFormat = pkgs.formats.ini { };
+
+ configDir = if pkgs.stdenv.hostPlatform.isDarwin then
+ "Library/Application Support"
+ else
+ config.xdg.configHome;
+
+in {
+ meta.maintainers = [ maintainers.polykernel ];
+
+ options.programs.watson = {
+ enable = mkEnableOption "watson, a wonderful CLI to track your time";
+
+ package = mkOption {
+ type = types.package;
+ default = pkgs.watson;
+ defaultText = literalExpression "pkgs.watson";
+ description = "Package providing the watson.";
+ };
+
+ enableBashIntegration = mkEnableOption "watson's bash integration" // {
+ default = true;
+ };
+
+ enableZshIntegration = mkEnableOption "watson's zsh integration" // {
+ default = true;
+ };
+
+ enableFishIntegration = mkEnableOption "watson's fish integration" // {
+ default = true;
+ };
+
+ settings = mkOption {
+ type = iniFormat.type;
+ default = { };
+ description = ''
+ Configuration written to
+ $XDG_CONFIG_HOME/watson/config on Linux or
+ $HOME/Library/Application Support/watson/config on Darwin.
+
+ See
+ for an example configuration.
+ '';
+ example = literalExpression ''
+ {
+ backend = {
+ url = "https://api.crick.fr";
+ token = "yourapitoken";
+ };
+
+ options = {
+ stop_on_start = true;
+ stop_on_restart = false;
+ date_format = "%Y.%m.%d";
+ time_format = "%H:%M:%S%z";
+ week_start = "monday";
+ log_current = false;
+ pager = true;
+ report_current = false;
+ reverse_log = true;
+ };
+ }
+ '';
+ };
+ };
+
+ config = mkIf cfg.enable {
+ home.packages = [ cfg.package ];
+
+ home.file."${configDir}/watson/config" = mkIf (cfg.settings != { }) {
+ source = iniFormat.generate "watson-config" cfg.settings;
+ };
+
+ programs.bash.initExtra = mkIf cfg.enableBashIntegration ''
+ source ${cfg.package}/share/bash-completion/completions/watson
+ '';
+
+ programs.zsh.initExtra = mkIf cfg.enableZshIntegration ''
+ source ${cfg.package}/share/zsh/site-functions/_watson
+ '';
+
+ programs.fish.shellInit = mkIf cfg.enableFishIntegration ''
+ source ${cfg.package}/share/fish/vendor_completions.d/watson.fish
+ '';
+ };
+}
diff --git a/tests/default.nix b/tests/default.nix
index 1bd8ff29..e1e5f430 100644
--- a/tests/default.nix
+++ b/tests/default.nix
@@ -101,6 +101,7 @@ import nmt {
./modules/programs/tmux
./modules/programs/topgrade
./modules/programs/vscode
+ ./modules/programs/watson
./modules/programs/zplug
./modules/programs/zsh
./modules/xresources
diff --git a/tests/modules/programs/watson/default.nix b/tests/modules/programs/watson/default.nix
new file mode 100644
index 00000000..32df633d
--- /dev/null
+++ b/tests/modules/programs/watson/default.nix
@@ -0,0 +1,4 @@
+{
+ watson-empty-settings = ./empty-settings.nix;
+ watson-example-settings = ./example-settings.nix;
+}
diff --git a/tests/modules/programs/watson/empty-settings.nix b/tests/modules/programs/watson/empty-settings.nix
new file mode 100644
index 00000000..8e047466
--- /dev/null
+++ b/tests/modules/programs/watson/empty-settings.nix
@@ -0,0 +1,19 @@
+{ config, lib, pkgs, ... }:
+
+with lib;
+
+{
+ programs.watson = {
+ enable = true;
+ package = config.lib.test.mkStubPackage { };
+ };
+
+ nmt.script = let
+ configDir = if pkgs.stdenv.hostPlatform.isDarwin then
+ "home-files/Library/Application Support"
+ else
+ "home-files/.config";
+ in ''
+ assertPathNotExists ${configDir}/watson/config
+ '';
+}
diff --git a/tests/modules/programs/watson/example-settings-expected.ini b/tests/modules/programs/watson/example-settings-expected.ini
new file mode 100644
index 00000000..e148b12e
--- /dev/null
+++ b/tests/modules/programs/watson/example-settings-expected.ini
@@ -0,0 +1,14 @@
+[backend]
+token=yourapitoken
+url=https://api.crick.fr
+
+[options]
+date_format=%Y.%m.%d
+log_current=false
+pager=true
+report_current=false
+reverse_log=true
+stop_on_restart=false
+stop_on_start=true
+time_format=%H:%M:%S%z
+week_start=monday
diff --git a/tests/modules/programs/watson/example-settings.nix b/tests/modules/programs/watson/example-settings.nix
new file mode 100644
index 00000000..f81f1ac8
--- /dev/null
+++ b/tests/modules/programs/watson/example-settings.nix
@@ -0,0 +1,40 @@
+{ config, lib, pkgs, ... }:
+
+with lib;
+
+{
+ programs.watson = {
+ enable = true;
+ package = config.lib.test.mkStubPackage { };
+
+ settings = {
+ backend = {
+ url = "https://api.crick.fr";
+ token = "yourapitoken";
+ };
+
+ options = {
+ stop_on_start = true;
+ stop_on_restart = false;
+ date_format = "%Y.%m.%d";
+ time_format = "%H:%M:%S%z";
+ week_start = "monday";
+ log_current = false;
+ pager = true;
+ report_current = false;
+ reverse_log = true;
+ };
+ };
+ };
+
+ nmt.script = let
+ configDir = if pkgs.stdenv.hostPlatform.isDarwin then
+ "home-files/Library/Application Support"
+ else
+ "home-files/.config";
+ in ''
+ assertFileContent \
+ "${configDir}/watson/config" \
+ ${./example-settings-expected.ini}
+ '';
+}