~sumner/home-manager-config

home-manager-config/modules/window-manager/i3status-rust.nix -rw-r--r-- 5.8 KiB
e986663dSumner Evans display: add coruscant Dell monitor configs 5 hours ago
                                                                                
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
{ config, lib, pkgs, ... }: with lib; {
  options = {
    laptop.enable = mkEnableOption "configuration that only applies to laptops";
    networking.interfaces = mkOption {
      type = types.listOf types.str;
      description = "A list of the network interfaces on the machine";
      default = [ ];
    };
    programs.i3status-rust.extraBlocks = mkOption {
      type = types.listOf (types.attrsOf types.anything);
      description = "A list of extra blocks to add.";
      default = [ ];
    };
  };

  config = mkIf (config.wayland.enable || config.xorg.enable) {
    programs.i3status-rust = {
      enable = true;

      bars = {
        top =
          let
            cu = "${pkgs.coreutils}/bin";
            dunstctl = "${pkgs.dunst}/bin/dunstctl";
            home = config.home.homeDirectory;
            homeTmp = "${config.home.homeDirectory}/tmp";
            nmcli = "${pkgs.networkmanager}/bin/nmcli";
            parseRollingPingScript = pkgs.writeShellScriptBin "parse-rolling-ping" ''
              ${cu}/cat ${homeTmp}/rolling_ping | ${pkgs.gnugrep}/bin/grep "fail" > /dev/null
              [[ $? == 0 ]] && printf "∞" && exit 0
              printf "%0.3f" $(cat ${homeTmp}/rolling_ping | ${pkgs.jq}/bin/jq -s add/length)
            '';
          in
          {
            icons = "awesome";
            theme = "slick";

            blocks = map (x: builtins.removeAttrs x [ "priority" ]) (
              sort (a: b: a.priority < b.priority) (
                [
                  # Common blocks
                  {
                    block = "custom";
                    command = "echo  $(ls ${home}/.offlinemsmtp-outbox | ${cu}/wc -l)";
                    interval = 10;
                    priority = 0;
                  }
                  {
                    block = "maildir";
                    interval = 10;
                    inboxes = map (f: "${home}/Mail/${f}/INBOX") [ "Personal" "Gmail" ];
                    threshold_warning = 25;
                    threshold_critical = 50;
                    priority = 10;
                  }
                  {
                    block = "maildir";
                    interval = 10;
                    inboxes = map (f: "${home}/Mail/${f}/INBOX") [ "Work" ];
                    threshold_warning = 25;
                    threshold_critical = 50;
                    priority = 10;
                  }
                  {
                    block = "toggle";
                    text = "Send Email?";
                    command_state = "ls ${homeTmp}/offlinemsmtp-sendmail >/dev/null && echo 'Send Email'";
                    command_on = "${cu}/touch ${homeTmp}/offlinemsmtp-sendmail";
                    command_off = "${cu}/rm ${homeTmp}/offlinemsmtp-sendmail";
                    interval = 5;
                    priority = 20;
                  }
                  {
                    block = "memory";
                    format_mem = "{mem_used;G}";
                    format_swap = "{swap_used;G}";
                    warning_mem = 90;
                    warning_swap = 90;
                    critical_mem = 95;
                    critical_swap = 95;
                    priority = 30;
                  }
                  {
                    block = "music";
                    player = "sublimemusic";
                    buttons = [ (mkIf (!config.laptop.enable) "prev") "play" "next" ];
                    priority = 40;
                  }
                  {
                    # Ping time
                    block = "custom";
                    command = ''printf "P: %s" $(${parseRollingPingScript}/bin/parse-rolling-ping)'';
                    interval = 1;
                    priority = 70;
                  }
                  {
                    block = "sound";
                    step_width = 2;
                    priority = 90;
                  }
                  {
                    block = "time";
                    format = "%F %R:%S";
                    interval = 1;
                    priority = 100;
                  }
                ] ++ (
                  # Include a "net" block for each of the network interfaces.
                  # TODO look into using the networkmanager block here instead
                  imap0
                    (
                      i: dev: {
                        block = "net";
                        device = dev;
                        interval = 5;
                        format = "{ip}";
                        hide_missing = true;
                        hide_inactive = true;
                        priority = 80 + i;
                      }
                    )
                    config.networking.interfaces
                ) ++ (
                  optionals config.laptop.enable [
                    {
                      block = "backlight";
                      priority = 50;
                    }
                    {
                      block = "battery";
                      interval = 30;
                      format = "{percentage} {time}";
                      device = "BAT0";
                      priority = 110;
                    }
                  ]
                ) ++ (
                  # TODO need to figure out how to do this for Sway
                  optionals config.xorg.enable [
                    {
                      block = "toggle";
                      text = "DND";
                      command_state = "[[ $(${dunstctl} is-paused) == true ]]";
                      command_on = "${dunstctl} set-paused true";
                      command_off = "${dunstctl} set-paused false";
                      interval = 60;
                      priority = 120;
                    }
                  ]
                ) ++ config.programs.i3status-rust.extraBlocks
              )
            );
          };
      };
    };
  };
}