This repository has been archived by the owner on Sep 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings.nix
195 lines (166 loc) · 5.26 KB
/
settings.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
{ pkgs, lib, config, ...}:
with lib;
let
inherit (lib.attrsets) filterAttrs nameValuePair;
inherit (lib.lists) range forEach;
cfg = config.yusef.streamdeck;
# options for a single stream deck button
button-module = types.submodule {
options = {
button = mkOption {
type = types.int;
description = "button index for this button. range is 0 .. (num_buttons - 1)";
};
icon = mkOption {
type = types.nullOr types.str;
description = "path to image file";
default = null;
};
text = mkOption {
type = types.nullOr types.str;
description = "text label to display";
default = null;
};
command = mkOption {
type = types.nullOr types.str;
description = "command to execute when button is pressed";
default = null;
};
keys = mkOption {
type = types.nullOr types.str;
description = "keypress to trigger (x11 only)";
default = null;
};
switch-page = mkOption {
type = types.nullOr types.int;
description = "switch to streamdeck page";
default = null;
};
brightness-change = mkOption {
type = types.nullOr types.int;
description = "+/- amount to adjust streamdeck brightness";
default = null;
};
write = mkOption {
type = types.nullOr types.str;
description = "text to write (x11 only)";
default = null;
};
};
};
page-module = types.submodule {
options = {
page = mkOption {
type = types.int;
description = "page number. range 0 .. 9";
default = 0;
};
buttons = mkOption {
type = types.listOf button-module;
description = "buttons in this page";
default = [];
};
};
};
device-config-module = types.submodule {
options = {
device-id = mkOption {
type = types.str;
description = "device serial id. default is mine cause I'm lazy";
default = "DL51K1A63326";
};
num-buttons = mkOption {
type = types.int;
description = "number of buttons on your device";
default = 15;
};
brightness = mkOption {
type = types.nullOr types.int;
description = "stream deck brightness";
default = null;
};
brightness-dimmed = mkOption {
type = types.nullOr types.int;
description = "brightness when auto-dimmed";
default = null;
};
display-timeout = mkOption {
type = types.nullOr types.int;
description = "seconds of inactivity before auto-dimming";
default = null;
};
pages = mkOption {
type = types.listOf page-module;
description = "page definitions. docs TDB";
default = [];
};
};
};
# returns an attr set with fields numbered 0 - (num-1),
# whose values are empty attribute sets
empty-objects =
num:
(builtins.listToAttrs
(forEach
(range 0 (num - 1))
(i: (nameValuePair (toString i) {}))));
# returns an attribute set defining a button's properties,
# given a button-submodule nix expression
button-definition = b: filterAttrs
(n: v: v != null)
{
icon = b.icon;
text = b.text;
command = b.command;
keys = b.keys;
# the app uses pagenumber + 1 in the switch_page setting
switch_page = if (b.switch-page != null) then b.switch-page + 1 else null;
brightness_change = b.brightness-change;
write = b.write;
};
button-defs = page-buttons:
(builtins.listToAttrs
(forEach page-buttons
(b: (nameValuePair (toString b.button) (button-definition b)))));
full-page = num-buttons: page-buttons:
(empty-objects num-buttons) // (button-defs page-buttons);
blank-pages = num-buttons:
(builtins.listToAttrs
(forEach (range 0 10)
(i: nameValuePair (toString i) (empty-objects num-buttons))));
to-json = device-config: let
page-definitions =
(builtins.listToAttrs
(forEach device-config.pages
(p: nameValuePair
(toString p.page)
(full-page device-config.num-buttons p.buttons))));
obj = {
streamdeck_ui_version = 1;
state = {
"${device-config.device-id}" = (filterAttrs (n: v: v != null) {
buttons = (blank-pages device-config.num-buttons) // page-definitions;
brightness = device-config.brightness;
brightness_dimmed = device-config.brightness-dimmed;
display_timeout = device-config.display-timeout;
});
};
};
in (builtins.toJSON obj);
default-config = (import ./my-config.nix { inherit lib; inherit pkgs; });
in
{
options.yusef.streamdeck.settings = mkOption {
type = types.nullOr device-config-module;
description = "streamdeck-ui settings json file. will be linked to /etc/streamdeck_ui.json - you'll need to manually copy to ~/.streamdeck_ui.json - symlinks wont work, since it needs to be writable by the app";
default = default-config;
};
config = mkIf (cfg.enable && cfg.settings != null) {
environment.etc."streamdeck_ui.json" = {
source = pkgs.writeTextFile {
text = (to-json cfg.settings);
name = "streamdeck_ui.json";
};
};
};
}