fork/home-manager

git clone https://git.julia.blue/fork/home-manager

Florian Peterprograms.i3status-rust: reload on config change (#4466)e63a6b34

master
7.6 KiB266 linesraw
1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6
7  cfg = config.programs.i3status-rust;
8
9  settingsFormat = pkgs.formats.toml { };
10
11in {
12  meta.maintainers = with lib.maintainers; [ farlion thiagokokada ];
13
14  options.programs.i3status-rust = {
15    enable = mkEnableOption "a replacement for i3-status written in Rust";
16
17    bars = mkOption {
18      type = types.attrsOf (types.submodule {
19        options = {
20
21          blocks = mkOption {
22            type = settingsFormat.type;
23            default = [
24              { block = "cpu"; }
25              {
26                block = "disk_space";
27                path = "/";
28                info_type = "available";
29                interval = 20;
30                warning = 20.0;
31                alert = 10.0;
32                format = " $icon root: $available.eng(w:2) ";
33              }
34              {
35                block = "memory";
36                format = " $icon $mem_total_used_percents.eng(w:2) ";
37                format_alt = " $icon_swap $swap_used_percents.eng(w:2) ";
38              }
39              {
40                block = "sound";
41                click = [{
42                  button = "left";
43                  cmd = "pavucontrol";
44                }];
45              }
46              {
47                block = "time";
48                interval = 5;
49                format = " $timestamp.datetime(f:'%a %d/%m %R') ";
50              }
51            ];
52            description = ''
53              Configuration blocks to add to i3status-rust
54              {file}`config`. See
55              <https://github.com/greshake/i3status-rust/blob/master/blocks.md>
56              for block options.
57            '';
58            example = literalExpression ''
59              [
60                {
61                  block = "disk_space";
62                  path = "/";
63                  info_type = "available";
64                  interval = 60;
65                  warning = 20.0;
66                  alert = 10.0;
67                }
68                {
69                  block = "sound";
70                  format = " $icon $output_name {$volume.eng(w:2) |}";
71                  click = [
72                    {
73                      button = "left";
74                      cmd = "pavucontrol --tab=3";
75                    }
76                  ];
77                  mappings = {
78                    "alsa_output.pci-0000_00_1f.3.analog-stereo" = "";
79                    "bluez_sink.70_26_05_DA_27_A4.a2dp_sink" = "";
80                  };
81                }
82              ];
83            '';
84          };
85
86          settings = mkOption {
87            type = settingsFormat.type;
88            default = { };
89            description = ''
90              Any extra options to add to i3status-rust
91              {file}`config`.
92            '';
93            example = literalExpression ''
94              {
95                theme =  {
96                  theme = "solarized-dark";
97                  overrides = {
98                    idle_bg = "#123456";
99                    idle_fg = "#abcdef";
100                  };
101                };
102              }
103            '';
104          };
105
106          icons = mkOption {
107            type = types.str;
108            default = "none";
109            description = ''
110              The icons set to use. See
111              <https://github.com/greshake/i3status-rust/blob/master/doc/themes.md>
112              for a list of available icon sets.
113            '';
114            example = "awesome6";
115          };
116
117          theme = mkOption {
118            type = types.str;
119            default = "plain";
120            description = ''
121              The theme to use. See
122              <https://github.com/greshake/i3status-rust/blob/master/doc/themes.md>
123              for a list of available themes.
124            '';
125            example = "gruvbox-dark";
126          };
127        };
128      });
129
130      default = {
131        default = {
132          blocks = [
133            {
134              block = "disk_space";
135              path = "/";
136              info_type = "available";
137              interval = 60;
138              warning = 20.0;
139              alert = 10.0;
140            }
141            {
142              block = "memory";
143              format = " $icon mem_used_percents ";
144              format_alt = " $icon $swap_used_percents ";
145            }
146            {
147              block = "cpu";
148              interval = 1;
149            }
150            {
151              block = "load";
152              interval = 1;
153              format = " $icon $1m ";
154            }
155            { block = "sound"; }
156            {
157              block = "time";
158              interval = 60;
159              format = " $timestamp.datetime(f:'%a %d/%m %R') ";
160            }
161          ];
162        };
163      };
164      description = ''
165        Attribute set of i3status-rust bars, each with their own configuration.
166        Each bar {var}`name` generates a config file suffixed with
167        the bar's {var}`name` from the attribute set, like so:
168        {file}`config-''${name}.toml`.
169
170        This way, multiple config files can be generated, such as for having a
171        top and a bottom bar.
172
173        See
174        {manpage}`i3status-rust(1)`
175        for options.
176      '';
177      example = literalExpression ''
178        bottom = {
179          blocks = [
180            {
181               block = "disk_space";
182               path = "/";
183               info_type = "available";
184               interval = 60;
185               warning = 20.0;
186               alert = 10.0;
187             }
188             {
189               block = "memory";
190               format_mem = " $icon $mem_used_percents ";
191               format_swap = " $icon $swap_used_percents ";
192             }
193             {
194               block = "cpu";
195               interval = 1;
196             }
197             {
198               block = "load";
199               interval = 1;
200               format = " $icon $1m ";
201             }
202             { block = "sound"; }
203             {
204               block = "time";
205               interval = 60;
206               format = " $timestamp.datetime(f:'%a %d/%m %R') ";
207             }
208          ];
209          settings = {
210            theme =  {
211              theme = "solarized-dark";
212              overrides = {
213                idle_bg = "#123456";
214                idle_fg = "#abcdef";
215              };
216            };
217          };
218          icons = "awesome5";
219          theme = "gruvbox-dark";
220        };
221      '';
222    };
223
224    package = mkOption {
225      type = types.package;
226      default = pkgs.i3status-rust;
227      defaultText = literalExpression "pkgs.i3status-rust";
228      description = "Package providing i3status-rust";
229    };
230
231  };
232
233  config = mkIf cfg.enable {
234    assertions = [
235      (hm.assertions.assertPlatform "programs.i3status-rust" pkgs
236        platforms.linux)
237      {
238        assertion = lib.versionOlder cfg.package.version "0.31.0"
239          || lib.versionAtLeast cfg.package.version "0.31.2";
240        message =
241          "Only i3status-rust <0.31.0 or ≥0.31.2 is supported due to a config format incompatibility.";
242      }
243    ];
244
245    home.packages = [ cfg.package ];
246
247    xdg.configFile = mapAttrs' (cfgFileSuffix: cfgBar:
248      nameValuePair ("i3status-rust/config-${cfgFileSuffix}.toml") ({
249        onChange = ''
250          ${pkgs.procps}/bin/pkill -u $USER -USR2 i3status-rs || true
251        '';
252
253        source = settingsFormat.generate ("config-${cfgFileSuffix}.toml") ({
254          theme = if lib.versionAtLeast cfg.package.version "0.30.0" then {
255            theme = cfgBar.theme;
256          } else
257            cfgBar.theme;
258          icons = if lib.versionAtLeast cfg.package.version "0.30.0" then {
259            icons = cfgBar.icons;
260          } else
261            cfgBar.icons;
262          block = cfgBar.blocks;
263        } // cfgBar.settings);
264      })) cfg.bars;
265  };
266}