about summary refs log tree commit diff stats
path: root/hm/soispha/conf/taskwarrior/hooks/default.nix
blob: 31d97529ba8518f73ce810ef845873c0307eb1b1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
{
  sysLib,
  pkgs,
  lib,
  config,
  ...
}: let
  enforce_policies = sysLib.writeShellScriptWithLibrary {
    name = "bin";
    src = ./scripts/on-add_enforce-policies.sh;
    dependencies = with pkgs; [dash jq taskwarrior gnused gnugrep];
    replacementStrings = let
      mkProject = project: subproject:
        if builtins.isString subproject
        then {
          name = "${project.name}.${subproject}";
          prefix = null;
        }
        else let
          name = builtins.elemAt (builtins.attrNames subproject) 0;
        in {
          name = "${project.name}.${name}";
          subprojects = builtins.elemAt (builtins.attrValues subproject) 0;
          prefix = null;
        };

      mkProjectName = project:
        if builtins.hasAttr "subprojects" project
        then
          lib.lists.flatten ([project.name]
            ++ (builtins.map mkProjectName
              (builtins.map (mkProject project) project.subprojects)))
        else [project.name];
      projects = lib.lists.flatten (builtins.map mkProjectName (import ../projects {}));
      projects_newline = builtins.concatStringsSep "\n" projects;
      projects_comma = builtins.concatStringsSep ", " projects;
    in {
      PROJECTS_NEWLINE = projects_newline;
      PROJECTS_COMMA = projects_comma;
    };
  };
  track_timewarrior = pkgs.stdenv.mkDerivation {
    name = "track_timewarrior.taskwarrior-hook";
    propagatedBuildInputs = [
      pkgs.timewarrior
      pkgs.taskwarrior
      (pkgs.python3.withPackages (pythonPackages:
        with pythonPackages; [
          taskw
        ]))
    ];
    dontUnpack = true;
    installPhase = "install -Dm755 ${./scripts/on-modify_track-timewarrior.py} $out/bin/bin";
  };
  track_total_active_time = pkgs.stdenv.mkDerivation {
    name = "track_total_active_time.taskwarrior-hook";
    propagatedBuildInputs = [
      pkgs.taskwarrior
      (pkgs.python3.withPackages (pythonPackages:
        with pythonPackages; [
          taskw
        ]))
    ];
    dontUnpack = true;
    installPhase = "install -Dm755 ${./scripts/on-modify_track-total-active-time.py} $out/bin/bin";
  };

  mkSyncGitRepo = type: {
    name = "${hookPath}/${type}_sync-git-repo";
    value = {
      source = "${sysLib.writeShellScriptWithLibrary {
        name = "bin";
        src = ./scripts + "/${type}_sync-git-repo.sh";
        dependencies = with pkgs; [dash taskwarrior git];
      }}/bin/bin";
    };
  };
  sync_git_repos =
    builtins.listToAttrs (builtins.map mkSyncGitRepo ["on-add" "on-modify"]);
  hookPath = config.programs.taskwarrior.config.hooks.location;
in {
  home.file = {
    "${hookPath}/on-add_enforce-policies".source = "${enforce_policies}/bin/bin";
    "${hookPath}/on-modify_track-timewarrior".source = "${track_timewarrior}/bin/bin";
    "${hookPath}/on-modify_track-total-active-time".source = "${track_total_active_time}/bin/bin";
  } // sync_git_repos;
}