forked from scorpion-26/gBar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
module.nix
247 lines (234 loc) · 11.1 KB
/
module.nix
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
# Based on Hyprland's home-manager and NixOS module
self:
{ config
, lib
, pkgs
, ...
}:
with lib;
let
cfg = config.programs.gBar;
defaultGBarPackage = self.defaultPackage.x86_64-linux;
in {
options.programs.gBar = {
enable = mkEnableOption "Wether to enable gBar, a blazingly fast statusbar written in c++";
package = mkOption {
type = types.nullOr types.package;
default = defaultGBarPackage;
defaultText = literalExpression "<gBar flake>.packages.<system>.default";
example = literalExpression "<gBar flake>.packages.<system>.default.override { }";
description = ''
gBar package to use.
'';
};
config = mkOption {
default = {};
description = "Options to write to gBar config file, named as standard options";
type = types.submodule {
options = {
CPUThermalZone = mkOption {
type = types.nullOr types.str;
default = "/sys/devices/pci0000:00/0000:00:18.3/hwmon/hwmon2/temp1_input";
description = "path to the cpu thermal sensor, probably something in /sys/device";
};
SuspendCommand = mkOption {
type = types.str;
default = "systemctl suspend";
description = "The command to execute on suspend";
};
LockCommand = mkOption {
type = types.nullOr types.str;
default = "~/.config/scripts/sys.sh lock";
description = "The command to execute on lock";
};
ExitCommand = mkOption {
type = types.str;
default = "killall Hyprland";
description = "The command to execute on exit";
};
BatteryFolder = mkOption {
type = types.nullOr types.str;
default = "/sys/class/power_supply/BAT1";
description = "The folder, where the battery sensors reside";
};
WorkspaceSymbols = mkOption {
type = types.nullOr (types.listOf types.str);
default = [];
description = "A list of strings where the position in the list is the icon to change, overrides the default symbol";
};
DefaultWorkspaceSymbol = mkOption {
type = types.str;
default = "";
description = "The default symbol for the workspaces";
};
WorkspaceScrollOnMonitor = mkOption {
type = types.bool;
default = true;
description = "Scroll through the workspaces of the current monitor instead of all workspaces";
};
WorkspaceScrollInvert = mkOption {
type = types.bool;
default = false;
description = "When true: Scroll up -> Next workspace instead of previous workspace. Analogous with scroll down";
};
UseHyprlandIPC = mkOption {
type = types.bool;
default = false;
description = ''
Use Hyprland IPC instead of the ext_workspace protocol for workspace polling.
Hyprland IPC is *slightly* less performant (+0.1% one core), but way less bug prone,
since the protocol is not as feature complete as Hyprland IPC.
'';
};
Location = mkOption {
type = types.enum ["T" "B" "L" "R"];
default = "T";
description = "The location of the bar, enumerates to one capitalised letter as above";
};
CenterTime = mkOption {
type = types.bool;
default = true;
description = ''
Forces the time to be centered.
This can cause the right widget to clip outside, if there is not enough space on screen (e.g. when opening the text)
Setting this to false will definitely fix this issue, but it won't look very good, since it will be off-center.
So try to decrease "TimeSpace" first, before setting this configuration to false.
'';
};
TimeSpace = mkOption {
type = types.nullOr types.int;
default = 300;
description = ''
How much space should be reserved for the time widget. Setting this too high can cause the right widget to clip outside.
Therefore try to set it as low as possible if you experience clipping.
Although keep in mind, that a value that is too low can cause the widget to be be off-center,
which can also cause clipping.
If you can't find an optimal value, consider setting 'CenterTime' to false
'';
};
DateTimeStyle = mkOption {
type = types.nullOr types.str;
default = "%a %D - %H:%M:%S %Z";
description = "Set datetime style";
};
AudioInput = mkOption {
type = types.bool;
default = false;
description = "Adds a microphone volume widget";
};
AudioRevealer = mkOption {
type = types.bool;
default = false;
description = "Sets the audio slider to be on reveal (Just like the sensors) when true. Only affects the bar.";
};
AudioScrollSpeed = mkOption {
type = types.nullOr types.int;
default = 5;
description = "Sets the rate of change of the slider on each scroll. In Percent";
};
AudioNumbers = mkOption {
type = types.bool;
default = false;
description = "Display numbers instead of a slider for the two audio widgets. Doesn't affect the audio flyin";
};
AudioMinVolume = mkOption {
type = types.nullOr types.int;
default = 0;
description = "Limits the range of the audio slider. Only works for audio output. Slider 'empty' is AudioMinVolume, Slider 'full' is AudioMaxVolume";
};
AudioMaxVolume = mkOption {
type = types.nullOr types.int;
default = 100;
description = "";
};
NetworkAdapter = mkOption {
type = types.nullOr types.str;
default = "eno1";
description = "The network adapter to use. You can query /sys/class/net for all possible values";
};
NetworkWidget = mkOption {
type = types.bool;
default = true;
description = "Disables the network widget when set to false";
};
EnableSNI = mkOption {
type = types.bool;
default = true;
description = "Enable tray icons";
};
SNIIconSize = mkOption {
type = types.attrsOf types.int;
default = {};
description = "sets the icon size for a SNI icon, an attribute set where, for example you can put Discord = 23 as an attribute and thus make discord slightly smaller Set to * to apply to all";
};
SNIIconPaddingTop = mkOption {
type = types.attrsOf types.int;
default = {};
description = "Can be used to push the Icon down. Negative values are allowed same as IconSize with an attribute set";
};
# These set the range for the network widget. The widget changes colors at six intervals:
# - Below Min...Bytes ("under")
# - Between ]0%;25%]. 0% = Min...Bytes; 100% = Max...Bytes ("low")
# - Between ]25%;50%]. 0% = Min...Bytes; 100% = Max...Bytes ("mid-low")
# - Between ]50%;75%]. 0% = Min...Bytes; 100% = Max...Bytes ("mid-high")
# - Between ]75%;100%]. 0% = Min...Bytes; 100% = Max...Bytes ("high")
# - Above Max...Bytes ("over")
MinDownloadBytes = mkOption {
type = types.nullOr types.int;
default = 0;
description = "";
};
MaxDownloadBytes = mkOption {
type = types.nullOr types.int;
default = 10485760;
description = "";
};
MinUploadBytes = mkOption {
type = types.nullOr types.int;
default = 0;
description = "";
};
MaxUploadBytes = mkOption {
type = types.nullOr types.int;
default = 5242880;
description = "";
};
};
};
};
extraConfig = mkOption {
type = types.nullOr types.lines;
default = '' '';
description = ''
Configuration to write to ~/.config/gBar/config, if you want to use your own config then set this to null and home manager wont write anything, neither the config
'';
};
extraCSS = mkOption {
type = types.nullOr types.lines;
default = null;
description = ''
Configuration to write to ~/.config/gBar/style.css, if none nothing happens
'';
};
};
config = let
# Takes attributeset with an arbitrary value and returns it as an attrset of valid gBar options
applyVal = x:
let anyToString = a: if isBool a then boolToString a else toString a;
in attrsets.mapAttrs (name: value:
name + ": " + (anyToString value)) (filterAttrs (n2: v2: (isInt v2 || isString v2 || isBool v2))x);
extractLists = l:
(imap1 (i: v: "WorkspaceSymbol-${toString i}: " + v) l.WorkspaceSymbols) ++
(mapAttrsToList (n: v: "SNIIconSize: ${n}, ${toString v}") l.SNIIconSize) ++
(mapAttrsToList (n: v: "SNIIconPaddingTop: ${n}, ${toString v}") l.SNIIconPaddingTop);
gBarConfig = (concatMapStrings (x: x + "\n") (attrValues (applyVal cfg.config)))+(concatMapStrings (x: x+"\n") (extractLists cfg.config));
in mkIf cfg.enable {
home.packages = optional (cfg.package != null) cfg.package;
xdg.configFile."gBar/config" = mkIf (cfg.extraConfig != null) {
text = "# Generated by Home Manager\n" + gBarConfig + cfg.extraConfig;
};
xdg.configFile."gBar/style.css" = mkIf (cfg.extraCSS != null) {
text = cfg.extraCSS;
};
};
}