]> Git — Sourcephile - julm/julm-nix.git/blob - home-manager/profiles/arbtt.nix
nebula: fix forgotten uses of .wg instead of .sp
[julm/julm-nix.git] / home-manager / profiles / arbtt.nix
1 { pkgs, lib, config, ... }:
2 {
3 systemd.user = {
4 services.arbtt-capture = {
5 Service = {
6 Environment = [
7 "PATH=${lib.makeBinPath [
8 pkgs.coreutils
9 ]}"
10 ];
11 ExecStart = pkgs.writeShellScript "arbtt-capture-start" ''
12 set -eu
13 LOG=${config.xdg.dataHome}/arbtt/$(date +%Y).capture
14 ln -snf "$LOG" "${config.xdg.dataHome}/arbtt/capture.log"
15 exec ${pkgs.haskellPackages.arbtt}/bin/arbtt-capture --logfile="$LOG"
16 '';
17 Restart = "always";
18 };
19 Unit = {
20 Description = "Arbtt capture service";
21 PartOf = [ "graphical-session.target" ];
22 After = [
23 "graphical-session-pre.target"
24 ];
25 };
26 Install = {
27 WantedBy = [ "graphical-session.target" ];
28 };
29 };
30 };
31
32 home.activation.linkDotfiles = lib.hm.dag.entryAfter [ "writeBoundary" ] ''
33 ln -sfn ${config.xdg.dataHome}/arbtt $HOME/.arbtt
34 '';
35 xdg.dataFile."arbtt/categorize.cfg".text = lib.mkDefault ''
36 -- Simple rule that just tags the current program
37 $idle > 30 ==> tag inactive,
38 tag Program:$current.program,
39 '';
40 home.packages = [
41 pkgs.haskellPackages.arbtt
42 (pkgs.writeShellScriptBin "arbtt-stats-for" ''
43 set -eu
44 period=''${1-}
45 shift
46 case "$period" in
47 today)
48 today=$(date +"%Y-%m-%d")
49 echo "$today"
50 arbtt-stats -m 0.1 --filter='$date>='$today "$@"
51 ;;
52 week)
53 today=$(date +"%Y-%m-%d")
54 today=$(date -dlast-monday +%Y-%m-%d)
55 echo "$today to Now"
56 arbtt-stats -m 0.1 --filter='$date>='$today "$@"
57 ;;
58 month)
59 today=$(date +"%Y-%m-01")
60 echo "$today to Now"
61 arbtt-stats -m 0.01 --filter='$date>='$today "$@"
62 ;;
63 prevmonth)
64 startday=$(date --date="$(date +%Y-%m-15) -1 month" +'%Y-%m-01')
65 endday=$(date --date="$(date +%Y-%m-01) -1 day" +'%Y-%m-%d')
66 echo "$startday to $endday"
67 arbtt-stats -m 0.01 --filter='$date>='$startday' && $date<='$(date +%Y-%m-01) "$@"
68 ;;
69 prevday)
70 startday=$(date --date="$(date +%Y-%m-%d) -1 day" +'%Y-%m-%d')
71 endday=$(date +%Y-%m-%d)
72 echo "$startday"
73 arbtt-stats -m 0.1 --filter='$date>='$startday' && $date<='$endday "$@"
74 ;;
75 -d)
76 startday=$2
77 endday=$(date --date="$2 +1 day" +'%Y-%m-%d')
78 echo "$startday"
79 arbtt-stats -m 0.1 --filter='$date>='$startday' && $date<='$endday "$@"
80 ;;
81 *)
82 echo "Usage: arbtt [OPTIONS...]"
83 echo " today"
84 echo " week"
85 echo " month"
86 echo " prevmonth"
87 echo " prevday"
88 echo " -d [%Y-%m-%d]"
89 esac
90 '')
91 ];
92 }