-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hm-module.nix
171 lines (155 loc) · 4.42 KB
/
hm-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
hyprlux: {
pkgs,
lib,
config,
...
}: let
time = lib.types.strMatching ''^([0-1]?[0-9]|2[0-3]):[0-5][0-9]$'';
nightLightSubmodule = lib.types.submodule {
options = {
enabled = lib.mkOption {
description = "Enabled night light";
type = lib.types.bool;
default = false;
};
latitude = lib.mkOption {
description = "Your latitude";
type = with lib.types; nullOr (oneOf [int float]);
default = null;
};
longitude = lib.mkOption {
description = "Your longitude";
type = with lib.types; nullOr (oneOf [int float]);
default = null;
};
start_time = lib.mkOption {
description = "When to start night light";
type = lib.types.nullOr time;
default = "20:00";
};
end_time = lib.mkOption {
description = "When to end night light";
type = lib.types.nullOr time;
default = "06:00";
};
temperature = lib.mkOption {
description = "Night light temperature";
type = lib.types.int;
default = 3500;
};
};
};
vibranceSubmodule = lib.types.submodule {
options = {
window_class = lib.mkOption {
description = "Window class name or regex";
type = lib.types.str;
default = "";
};
window_title = lib.mkOption {
description = "Window title name or regex";
type = lib.types.str;
default = "";
};
strength = lib.mkOption {
description = "Vibrance strength (1-100)";
type = lib.types.int;
default = 100;
};
};
};
cfg = config.programs.hyprlux;
cfgFormat = pkgs.formats.toml {};
pkg = hyprlux.packages.${pkgs.system}.default;
in {
options.programs.hyprlux = {
enable = lib.mkEnableOption "Enable hyprlux";
package =
lib.mkPackageOption pkgs "hyprlux" {}
// {
default = pkg;
};
systemd.enable = lib.mkEnableOption "Use as a systemd service";
systemd.target = lib.mkOption {
type = lib.types.str;
default = "graphical-session.target";
example = "hyprland-session.target";
description = ''
The systemd target that will automatically start the Hyprlux service.
When setting this value to `"hyprland-session.target"`,
make sure to also enable {option}`wayland.windowManager.hyprland.systemd.enable`,
otherwise the service may never be started.
'';
};
night_light = lib.mkOption {
type = nightLightSubmodule;
description = "Night light settings";
default = {
enabled = false;
start_time = "20:00";
end_time = "06:00";
temperature = 3500;
};
example = {
enabled = true;
latitude = 46.056946;
longitude = 14.505751;
temperature = 3500;
};
};
vibrance_configs = lib.mkOption {
description = "List of vibrance configurations";
type = lib.types.listOf vibranceSubmodule;
default = [];
example = [
{
window_class = "^(steam_app_)(.*)$";
window_title = "";
strength = 100;
}
{
window_class = "Firefox";
window_title = "";
strength = 10;
}
];
};
hot_reload = lib.mkOption {
description = "Listen for config changes";
type = lib.types.bool;
default = false;
example = true;
};
};
config = lib.mkIf cfg.enable (lib.mkMerge [
{
home.packages = [cfg.package];
xdg.configFile."hypr/hyprlux.toml" = {
source = cfgFormat.generate "hyprlux.toml" {
night_light = lib.attrsets.filterAttrs (n: v: v != null) cfg.night_light;
vibrance_configs = cfg.vibrance_configs;
hot_reload = cfg.hot_reload;
};
};
}
(lib.mkIf cfg.systemd.enable {
systemd.user.services.hyprlux = {
Unit = {
Description = "Hyprlux shader manager service";
Documentation = "https://github.com/amadejkastelic/Hyprlux";
PartOf = ["graphical-session.target"];
After = ["graphical-session-pre.target"];
};
Service = {
ExecStart = "${cfg.package}/bin/hyprlux";
ExecReload = "${pkgs.coreutils}/bin/kill -SIGUSR2 $MAINPID";
Restart = "on-failure";
KillMode = "mixed";
};
Install = {
WantedBy = [cfg.systemd.target];
};
};
})
]);
}