-
Notifications
You must be signed in to change notification settings - Fork 9
/
hm-module.nix
390 lines (382 loc) · 11.4 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
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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
{
config,
lib,
pkgs,
...
}:
let
cfg = config.programs.nixcord;
inherit (lib)
mkEnableOption
mkOption
types
mkIf
mkMerge
attrsets
lists
;
dop = with types; coercedTo package (a: a.outPath) pathInStore;
recursiveUpdateAttrsList =
list:
if (builtins.length list <= 1) then
(builtins.elemAt list 0)
else
recursiveUpdateAttrsList (
[
(attrsets.recursiveUpdate (builtins.elemAt list 0) (builtins.elemAt list 1))
]
++ (lists.drop 2 list)
);
applyPostPatch =
pkg:
pkg.overrideAttrs {
postPatch = lib.concatLines (
lib.optional (cfg.userPlugins != { }) "mkdir -p src/userplugins"
++ lib.mapAttrsToList (
name: path:
"ln -s ${lib.escapeShellArg path} src/userplugins/${lib.escapeShellArg name} && ls src/userplugins"
) cfg.userPlugins
);
};
defaultVencord = applyPostPatch (
pkgs.callPackage ./vencord.nix { unstable = cfg.discord.vencord.unstable; }
);
in
{
options.programs.nixcord = {
enable = mkEnableOption "Enables Discord with Vencord";
discord = {
enable = mkOption {
type = types.bool;
default = true;
description = ''
Whether to enable discord
Disable to only install Vesktop
'';
};
package = mkOption {
type = types.package;
default = pkgs.discord;
description = ''
The Discord package to use
'';
};
configDir = mkOption {
type = types.path;
default = "${
if pkgs.stdenvNoCC.isLinux then
config.xdg.configHome
else
"${config.home.homeDirectory}/Library/Application Support"
}/discord";
description = "Config path for Discord";
};
vencord = {
enable = mkOption {
type = types.bool;
default = true;
description = "Enable Vencord (for non-vesktop)";
};
package = mkOption {
type = types.package;
default = defaultVencord;
description = ''
The Vencord package to use
'';
};
unstable = mkOption {
type = types.bool;
default = false;
description = "Enable unstable Vencord build from repository's master branch";
};
};
openASAR.enable = mkOption {
type = types.bool;
default = true;
description = "Enable OpenASAR (for non-vesktop)";
};
settings = mkOption {
type = types.attrs;
default = { };
description = ''
Settings to be placed in discordConfigDir/settings.json
'';
};
};
vesktop = {
enable = mkEnableOption ''
Whether to enable Vesktop
'';
package = mkOption {
type = types.package;
default = pkgs.vesktop;
description = ''
The Vesktop package to use
'';
};
configDir = mkOption {
type = types.path;
default = "${
if pkgs.stdenvNoCC.isLinux then
config.xdg.configHome
else
"${config.home.homeDirectory}/Library/Application Support"
}/vesktop";
description = "Config path for Vesktop";
};
settings = mkOption {
type = types.attrs;
default = { };
description = ''
Settings to be placed in vesktop.configDir/settings.json
'';
};
state = mkOption {
type = types.attrs;
default = { };
description = ''
Settings to be placed in vesktop.configDir/state.json
'';
};
};
package = mkOption {
type = with types; nullOr package;
default = null;
description = ''
Deprecated
The Discord package to use
'';
};
vesktopPackage = mkOption {
type = with types; nullOr package;
default = null;
description = ''
The Vesktop package to use
'';
};
configDir = mkOption {
type = types.path;
default = "${
if pkgs.stdenvNoCC.isLinux then
config.xdg.configHome
else
"${config.home.homeDirectory}/Library/Application Support"
}/Vencord";
description = "Vencord config directory";
};
vesktopConfigDir = mkOption {
type = with types; nullOr path;
default = null;
description = "Config path for Vesktop";
};
openASAR.enable = mkOption {
type = with types; nullOr bool;
default = null;
description = "Enable OpenASAR (for non-vesktop)";
};
quickCss = mkOption {
type = types.str;
default = "";
description = "Vencord quick CSS";
};
config = {
notifyAboutUpdates = mkEnableOption "Notify when updates are available";
autoUpdate = mkEnableOption "Automaticall update Vencord";
autoUpdateNotification = mkEnableOption "Notify user about auto updates";
useQuickCss = mkEnableOption "Enable quick CSS file";
themeLinks = mkOption {
type = with types; listOf str;
default = [ ];
description = "A list of links to online vencord themes";
example = [ "https://raw.githubusercontent.com/rose-pine/discord/main/rose-pine.theme.css" ];
};
enabledThemes = mkOption {
type = with types; listOf str;
default = [ ];
description = "A list of themes to enable from themes directory";
};
enableReactDevtools = mkEnableOption "Enable React developer tools";
frameless = mkEnableOption "Make client frameless";
transparent = mkEnableOption "Enable client transparency";
disableMinSize = mkEnableOption "Disable minimum window size for client";
plugins = import ./plugins.nix { inherit lib; };
};
vesktopConfig = mkOption {
type = types.attrs;
default = { };
description = ''
additional config to be added to programs.nixcord.config
for vesktop only
'';
};
vencordConfig = mkOption {
type = types.attrs;
default = { };
description = ''
additional config to be added to programs.nixcord.config
for vencord only
'';
};
extraConfig = mkOption {
type = types.attrs;
default = { };
description = ''
additional config to be added to programs.nixcord.config
for both vencord and vesktop
'';
};
userPlugins =
let
regex = "github:([[:alnum:].-]+)/([[:alnum:]/-]+)/([0-9a-f]{40})";
coerce =
value:
let
matches = builtins.match regex value;
owner = builtins.elemAt matches 0;
repo = builtins.elemAt matches 1;
rev = builtins.elemAt matches 2;
in
builtins.fetchGit {
url = "https://github.com/${owner}/${repo}";
inherit rev;
};
in
mkOption {
type = with types; attrsOf (coercedTo (strMatching regex) coerce dop);
description = "User plugin to fetch and install. Note that any json required must be enabled in extraConfig";
default = { };
example = {
someCoolPlugin = "github:someUser/someCoolPlugin/someHashHere";
};
};
parseRules = {
upperNames = mkOption {
type = with types; listOf str;
description = "option names to become UPPER_SNAKE_CASE";
default = [ ];
};
lowerPluginTitles = mkOption {
type = with types; listOf str;
description = "plugins with lowercase names in json";
default = [ ];
example = [ "petpet" ];
};
fakeEnums = {
zero = mkOption {
type = with types; listOf str;
description = "strings to evaluate to 0 in JSON";
default = [ ];
};
one = mkOption {
type = with types; listOf str;
description = "strings to evaluate to 1 in JSON";
default = [ ];
};
two = mkOption {
type = with types; listOf str;
description = "strings to evaluate to 2 in JSON";
default = [ ];
};
three = mkOption {
type = with types; listOf str;
description = "strings to evaluate to 3 in JSON";
default = [ ];
};
four = mkOption {
type = with types; listOf str;
description = "strings to evaluate to 4 in JSON";
default = [ ];
};
# I've never seen a plugin with more than 5 options for 1 setting
};
};
};
config =
let
parseRules = cfg.parseRules;
inherit (pkgs.callPackage ./lib.nix { inherit lib parseRules; })
mkVencordCfg
;
vencord = applyPostPatch cfg.discord.vencord.package;
isQuickCssUsed =
appConfig:
(cfg.config.useQuickCss || appConfig ? "useQuickCss" && appConfig.useQuickCss)
&& cfg.quickCss != "";
in
mkIf cfg.enable (mkMerge [
{
assertions = [
{
assertion = !(cfg.discord.vencord.package != defaultVencord && cfg.discord.vencord.unstable);
message = "programs.nixcord.discord.vencord: Cannot set both 'package' and 'unstable = true'. Choose one or the other.";
}
];
home.packages = [
(mkIf cfg.discord.enable (
cfg.discord.package.override {
withVencord = cfg.discord.vencord.enable;
withOpenASAR = cfg.discord.openASAR.enable;
inherit vencord;
}
))
(mkIf cfg.vesktop.enable (
cfg.vesktop.package.override {
withSystemVencord = true;
inherit vencord;
}
))
];
}
(mkIf cfg.discord.enable (mkMerge [
# QuickCSS
(mkIf (isQuickCssUsed cfg.vencordConfig) {
home.file."${cfg.configDir}/settings/quickCss.css".text = cfg.quickCss;
})
# Vencord Settings
{
home.file."${cfg.configDir}/settings/settings.json".text = builtins.toJSON (
mkVencordCfg (recursiveUpdateAttrsList [
cfg.config
cfg.extraConfig
cfg.vencordConfig
])
);
}
# Client Settings
(mkIf (cfg.discord.settings != { }) {
home.file."${cfg.discord.configDir}/settings.json".text =
builtins.toJSON mkVencordCfg cfg.discord.settings;
})
]))
(mkIf cfg.vesktop.enable (mkMerge [
# QuickCSS
(mkIf (isQuickCssUsed cfg.vesktopConfig) {
home.file."${cfg.vesktop.configDir}/settings/quickCss.css".text = cfg.quickCss;
})
# Vencord Settings
{
home.file."${cfg.vesktop.configDir}/settings/settings.json".text = builtins.toJSON (
mkVencordCfg (recursiveUpdateAttrsList [
cfg.config
cfg.extraConfig
cfg.vesktopConfig
])
);
}
# Vesktop Client Settings
(mkIf (cfg.vesktop.settings != { }) {
home.file."${cfg.vesktop.configDir}/settings.json".text =
builtins.toJSON mkVencordCfg cfg.vesktopSettings;
})
# Vesktop Client State
(mkIf (cfg.vesktop.state != { }) {
home.file."${cfg.vesktop.configDir}/state.json".text =
builtins.toJSON mkVencordCfg cfg.vesktopState;
})
]))
# Warnings
{
warnings = import ./warnings.nix { inherit cfg mkIf; };
}
]);
}