fork/home-manager

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

Robert HelgessonMerge PR #421575790441

master
5.0 KiB201 linesraw
1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6  cfg = config.programs.i3status;
7
8  enabledModules = filterAttrs (n: v: v.enable) cfg.modules;
9
10  formatOrder = n: ''order += "${n}"'';
11
12  formatModule = n: v:
13    let
14      formatLine = n: v:
15        let
16          formatValue = v:
17            if isBool v then
18              (if v then "true" else "false")
19            else if isString v then
20              ''"${v}"''
21            else
22              toString v;
23        in "${n} = ${formatValue v}";
24    in ''
25      ${n} {
26        ${concatStringsSep "\n  " (mapAttrsToList formatLine v)}
27      }
28    '';
29
30  settingsType = with types; attrsOf (oneOf [ bool int str ]);
31
32  sortAttrNamesByPosition = comparator: set:
33    let pos = n: set."${n}".position;
34    in sort (a: b: comparator (pos a) (pos b)) (attrNames set);
35in {
36  meta.maintainers = [ hm.maintainers.justinlovinger ];
37
38  options.programs.i3status = {
39    enable = mkEnableOption "i3status";
40
41    enableDefault = mkOption {
42      type = types.bool;
43      default = true;
44      description = ''
45        Whether or not to enable
46        the default configuration.
47      '';
48    };
49
50    general = mkOption {
51      type = settingsType;
52      default = { };
53      description = ''
54        Configuration to add to i3status {file}`config`
55        `general` section.
56        See
57        {manpage}`i3status(1)`
58        for options.
59      '';
60      example = literalExpression ''
61        {
62          colors = true;
63          color_good = "#e0e0e0";
64          color_degraded = "#d7ae00";
65          color_bad = "#f69d6a";
66          interval = 1;
67        }
68      '';
69    };
70
71    modules = mkOption {
72      type = types.attrsOf (types.submodule {
73        options = {
74          enable = mkOption {
75            type = types.bool;
76            default = true;
77            description = ''
78              Whether or not to enable this module.
79            '';
80          };
81          position = mkOption {
82            type = with types; either int float;
83            description = ''
84              Position of this module in i3status `order`.
85            '';
86          };
87          settings = mkOption {
88            type = settingsType;
89            default = { };
90            description = ''
91              Configuration to add to this i3status module.
92              See
93              {manpage}`i3status(1)`
94              for options.
95            '';
96            example = literalExpression ''
97              {
98                format = "♪ %volume";
99                format_muted = "♪ muted (%volume)";
100                device = "pulse:1";
101              }
102            '';
103          };
104        };
105      });
106      default = { };
107      description = ''
108        Modules to add to i3status {file}`config` file.
109        See
110        {manpage}`i3status(1)`
111        for options.
112      '';
113      example = literalExpression ''
114        {
115          "volume master" = {
116            position = 1;
117            settings = {
118              format = "♪ %volume";
119              format_muted = "♪ muted (%volume)";
120              device = "pulse:1";
121            };
122          };
123          "disk /" = {
124            position = 2;
125            settings = {
126              format = "/ %avail";
127            };
128          };
129        }
130      '';
131    };
132
133    package = mkPackageOption pkgs "i3status" { };
134  };
135
136  config = mkIf cfg.enable {
137    programs.i3status = mkIf cfg.enableDefault {
138      general = {
139        colors = mkDefault true;
140        interval = mkDefault 5;
141      };
142
143      modules = {
144        ipv6 = { position = mkDefault 1; };
145
146        "wireless _first_" = {
147          position = mkDefault 2;
148          settings = {
149            format_up = mkDefault "W: (%quality at %essid) %ip";
150            format_down = mkDefault "W: down";
151          };
152        };
153
154        "ethernet _first_" = {
155          position = mkDefault 3;
156          settings = {
157            format_up = mkDefault "E: %ip (%speed)";
158            format_down = mkDefault "E: down";
159          };
160        };
161
162        "battery all" = {
163          position = mkDefault 4;
164          settings = { format = mkDefault "%status %percentage %remaining"; };
165        };
166
167        "disk /" = {
168          position = mkDefault 5;
169          settings = { format = mkDefault "%avail"; };
170        };
171
172        load = {
173          position = mkDefault 6;
174          settings = { format = mkDefault "%1min"; };
175        };
176
177        memory = {
178          position = mkDefault 7;
179          settings = {
180            format = mkDefault "%used | %available";
181            threshold_degraded = mkDefault "1G";
182            format_degraded = mkDefault "MEMORY < %available";
183          };
184        };
185
186        "tztime local" = {
187          position = mkDefault 8;
188          settings = { format = mkDefault "%Y-%m-%d %H:%M:%S"; };
189        };
190      };
191    };
192
193    home.packages = [ cfg.package ];
194
195    xdg.configFile."i3status/config".text = concatStringsSep "\n" ([ ]
196      ++ optional (cfg.general != { }) (formatModule "general" cfg.general)
197      ++ map formatOrder (sortAttrNamesByPosition lessThan enabledModules)
198      ++ mapAttrsToList formatModule
199      (mapAttrs (n: v: v.settings) enabledModules));
200  };
201}