aboutsummaryrefslogtreecommitdiffstats
path: root/modules/by-name/ta/taskwarrior/module.nix
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--modules/by-name/ta/taskwarrior/module.nix155
1 files changed, 125 insertions, 30 deletions
diff --git a/modules/by-name/ta/taskwarrior/module.nix b/modules/by-name/ta/taskwarrior/module.nix
index 0a942820..3d53706c 100644
--- a/modules/by-name/ta/taskwarrior/module.nix
+++ b/modules/by-name/ta/taskwarrior/module.nix
@@ -1,44 +1,139 @@
{
lib,
config,
+ pkgs,
...
}: let
cfg = config.soispha.programs.taskwarrior;
+
+ hooksDir =
+ pkgs.runCommandNoCCLocal "mk-taskwarrior-hooks" {}
+ (''
+ mkdir "$out"
+ ''
+ + (builtins.concatStringsSep "\n"
+ (lib.attrsets.mapAttrsToList
+ (name: value: ''
+ ln --symbolic "${lib.getExe value.executable}" "$out/${value.mode}_${name}"
+ '')
+ cfg.hooks)));
+
+ mkHook = mode: deps: path: {
+ inherit mode;
+
+ executable = pkgs.writeShellApplication {
+ name = "add-hook-${builtins.baseNameOf path}";
+ runtimeInputs = [pkgs.taskwarrior pkgs.coreutils] ++ deps;
+ inheritPath = false;
+ text =
+ # bash
+ ''
+ die() {
+ echo "$@"
+ exit 1
+ }
+
+ enable_hook_dbg() {
+ debug_hooks="$(task _get rc.debug.hooks)"
+ [ "$debug_hooks" ] && [ "$debug_hooks" -ge 1 ] && set -x
+ }
+
+ addedCall() {
+ ${builtins.readFile path}
+ }
+
+ ${
+ if mode == "on-modify"
+ then "read -r old_task"
+ else "old_task=NULL"
+ }
+ read -r new_task
+ # We don't change the task, thus immediately return the JSON
+ echo "$new_task"
+
+ enable_hook_dbg
+ addedCall "$new_task" "$old_task"
+
+ exit 0
+ '';
+ };
+ };
in {
options.soispha.programs.taskwarrior = {
- enable = lib.mkEnableOption "taskwarrior-secrets";
+ enable = lib.mkEnableOption "taskwarrior";
+
+ includeFiles = lib.mkOption {
+ type = lib.types.attrsOf lib.types.path;
+ description = "Extra files to include in the taskwarrior config";
+ default = {};
+ apply = value:
+ builtins.concatStringsSep "\n"
+ (builtins.map (path: "include ${path}")
+ (builtins.attrValues value));
+ };
+
+ hooks = lib.mkOption {
+ description = "Map hook names to their values";
+ type = lib.types.attrsOf (lib.types.submodule {
+ options = {
+ mode = lib.mkOption {
+ type = lib.types.enum ["on-add" "on-modify"];
+ description = "The type of the hook";
+ };
+ executable = lib.mkOption {
+ type = lib.types.package;
+ description = "The executable to call.";
+ };
+ };
+ });
+ };
};
- # HACK: Migrating the whole `taskwarrior` setup is right now unrealistic, as the module is
- # tightly coupled with the `firefox` module, and `neorg` script.
- # But to work around the fact that setting the `age` secrets in the legacy module is
- # impossible, this module was created as work-around until the `taskwarrior` module can
- # be fully migrated. <2024-10-18>
- config = lib.mkIf cfg.enable {
- age.secrets = {
- taskserverPrivate = {
- file = ./secrets/private.key;
- mode = "700";
- owner = "soispha";
- group = "users";
- };
- taskserverPublic = {
- file = ./secrets/public.cert;
- mode = "700";
- owner = "soispha";
- group = "users";
- };
- taskserverCA = {
- file = ./secrets/ca.cert;
- mode = "700";
- owner = "soispha";
- group = "users";
+ config = {
+ lib.taskwarrior = {
+ mkHook = mkHook;
+ };
+
+ home-manager.users.soispha = lib.mkIf cfg.enable {
+ services.taskwarrior-sync = {
+ enable = true;
};
- taskserverCredentials = {
- file = ./secrets/credentials;
- mode = "700";
- owner = "soispha";
- group = "users";
+
+ programs.taskwarrior = {
+ enable = true;
+ colorTheme = ./nord.theme;
+ extraConfig = cfg.includeFiles;
+
+ config = {
+ complete.all.tags = true;
+ list.all = {
+ projects = true;
+ tags = true;
+ };
+
+ regex = true;
+ weekstart = "Monday";
+
+ uda = {
+ total_active_time = {
+ type = "duration";
+ label = "Total active time";
+ };
+ };
+
+ alias = {
+ mod = "modify";
+ };
+ color = true;
+
+ hooks.location = "${hooksDir}";
+
+ urgency.uda.priority = {
+ H.coefficient = 6.0;
+ M.coefficient = 0;
+ L.coefficient = -1.8;
+ };
+ };
};
};
};