-
Notifications
You must be signed in to change notification settings - Fork 67
/
workspace.nix
370 lines (343 loc) · 14.8 KB
/
workspace.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
# General workspace behavior settings:
{ config, lib, pkgs, ... }:
let
cfg = config.programs.plasma;
inherit (import ../lib/wallpapers.nix { inherit lib; }) wallpaperPictureOfTheDayType wallpaperSlideShowType wallpaperFillModeTypes;
cursorType = with lib.types; submodule {
options = {
theme = lib.mkOption {
type = nullOr str;
default = null;
example = "Breeze_Snow";
description = "The Plasma cursortheme. Run plasma-apply-cursortheme --list-themes for valid options.";
};
size = lib.mkOption {
type = nullOr ints.positive;
default = null;
example = 24;
description = "The size of the cursor. See the settings GUI for allowed sizes for each cursortheme.";
};
};
};
anyThemeSet = (cfg.workspace.theme != null ||
cfg.workspace.colorScheme != null ||
(cfg.workspace.cursor != null && cfg.workspace.cursor.theme != null) ||
cfg.workspace.lookAndFeel != null ||
cfg.workspace.iconTheme != null);
splashScreenEngineDetect = theme: (if (theme == "None") then "none" else "KSplashQML");
in
{
imports = [
(lib.mkRenamedOptionModule [ "programs" "plasma" "workspace" "cursorTheme" ] [ "programs" "plasma" "workspace" "cursor" "theme" ])
];
options.programs.plasma.workspace = {
clickItemTo = lib.mkOption {
type = with lib.types; nullOr (enum [ "open" "select" ]);
default = null;
description = ''
Clicking files or folders should open or select them.
'';
};
tooltipDelay = lib.mkOption {
type = with lib.types; nullOr ints.positive;
default = null;
example = 5;
description = ''
The delay in milliseconds before an element's tooltip is shown when hovered over.
'';
};
theme = lib.mkOption {
type = with lib.types; nullOr str;
default = null;
example = "breeze-dark";
description = ''
The Plasma theme. Run plasma-apply-desktoptheme --list-themes for valid options.
'';
};
colorScheme = lib.mkOption {
type = with lib.types; nullOr str;
default = null;
example = "BreezeDark";
description = ''
The Plasma colorscheme. Run plasma-apply-colorscheme --list-schemes for valid options.
'';
};
cursor = lib.mkOption {
type = lib.types.nullOr cursorType;
default = null;
example = { theme = "Breeze_Snow"; size = 24; };
description = ''
Allows to configure the cursor in plasma. Both the theme and size are configurable.
'';
};
lookAndFeel = lib.mkOption {
type = with lib.types; nullOr str;
default = null;
example = "org.kde.breezedark.desktop";
description = ''
The Plasma look and feel theme. Run plasma-apply-lookandfeel --list for valid options.
'';
};
iconTheme = lib.mkOption {
type = with lib.types; nullOr str;
default = null;
example = "Papirus";
description = ''
The Plasma icon theme.
'';
};
wallpaper = lib.mkOption {
type = with lib.types; nullOr path;
default = null;
example = lib.literalExpression ''"''${pkgs.kdePackages.plasma-workspace-wallpapers}/share/wallpapers/Kay/contents/images/1080x1920.png"'';
description = ''
The Plasma wallpaper. Can be either be the path to an image file or a kpackage.
'';
};
wallpaperSlideShow = lib.mkOption {
type = lib.types.nullOr wallpaperSlideShowType;
default = null;
example = lib.literalExpression ''{ path = "''${pkgs.kdePackages.plasma-workspace-wallpapers}/share/wallpapers/"; }'';
description = ''
Allows you to set wallpaper slideshow. Needs a directory of your wallpapers and an interval length.
'';
};
wallpaperPictureOfTheDay = lib.mkOption {
type = lib.types.nullOr wallpaperPictureOfTheDayType;
default = null;
example = { provider = "apod"; };
description = ''
Allows you to set wallpaper using the picture of the day plugin. Needs the provider.
'';
};
wallpaperPlainColor = lib.mkOption {
type = with lib.types; nullOr str;
default = null;
example = "0,64,174,256";
description = ''
Allows you to set wallpaper using a plain color. Color is a comma-seperated R,G,B,A string. Alpha optional (default is 256).
'';
};
wallpaperFillMode = lib.mkOption {
type = with lib.types; nullOr (enum (builtins.attrNames wallpaperFillModeTypes));
default = null;
example = "stretch";
description = ''
Defines how the wallpaper should be displayed on the screen.
Applies only to wallpaperPictureOfTheDay or wallpaperSlideShow.
'';
apply = value: if value == null then null else (builtins.toString wallpaperFillModeTypes.${value});
};
soundTheme = lib.mkOption {
type = with lib.types; nullOr str;
default = null;
example = "freedesktop";
description = ''
The sound-theme to use with plasma.
'';
};
splashScreen = {
engine = lib.mkOption {
type = with lib.types; nullOr str;
default = null;
example = "none";
description = ''
The engine for the splash-screen theme. If not specified it will try
to set an appropriate engine for you, but if this doesn't work you
might want to manually specify this.
'';
};
theme = lib.mkOption {
type = with lib.types; nullOr str;
default = null;
example = "None";
description = ''
The splash-screen theme shown at login. To see available values see the
Theme key in ~/.config/ksplashrc after applying the splash-screen via
the settings app. Can also be set to "None" to disable the splash-screen
altogether.
'';
};
};
windowDecorations = {
library = lib.mkOption {
type = with lib.types; nullOr str;
default = null;
example = "org.kde.kwin.aurorae";
description = ''
The library for the window decorations theme. To see available values
see the library key in the org.kde.kdecoration2 section of
~/.config/kwinrc after applying the window-decoration via the
settings app.
'';
};
theme = lib.mkOption {
type = with lib.types; nullOr str;
default = null;
example = "__aurorae__svg__CatppuccinMocha-Modern";
description = ''
The window decorations theme. To see available values see the theme key
in the org.kde.kdecoration2 section of ~/.config/kwinrc after
applying the window-decoration via the settings app.
'';
};
};
};
config = (lib.mkIf cfg.enable {
assertions = [
{
assertion =
let
wallpapers = with cfg.workspace; [ wallpaperSlideShow wallpaper wallpaperPictureOfTheDay wallpaperPlainColor ];
in
lib.count (x: x != null) wallpapers <= 1;
message = "Can set only one of wallpaper, wallpaperSlideShow, wallpaperPictureOfTheDay, and wallpaperPlainColor.";
}
{
assertion = (cfg.workspace.splashScreen.engine == null || cfg.workspace.splashScreen.theme != null);
message = ''
Cannot set plasma.workspace.splashScreen.engine without a
corresponding theme.
'';
}
{
assertion = !(lib.xor (cfg.workspace.windowDecorations.theme == null) (cfg.workspace.windowDecorations.library == null));
message = ''
Must set both plasma.workspace.windowDecorations.library and
plasma.workspace.windowDecorations.theme or none.
'';
}
];
warnings = (if
((cfg.workspace.lookAndFeel != null) &&
(cfg.workspace.splashScreen.theme != null ||
cfg.workspace.windowDecorations.theme != null)) then
[
''Setting lookAndFeel together with splashScreen or windowDecorations in
plasma-manager is not recommended since lookAndFeel themes often
override these settings. Consider setting each part in the lookAndFeel
theme manually.''
] else [ ]);
programs.plasma.configFile = (lib.mkMerge [
{
kdeglobals = {
KDE.SingleClick = (lib.mkIf (cfg.workspace.clickItemTo != null) (cfg.workspace.clickItemTo == "open"));
Sounds.Theme = (lib.mkIf (cfg.workspace.soundTheme != null) cfg.workspace.soundTheme);
};
plasmarc = (lib.mkIf (cfg.workspace.tooltipDelay != null) {
PlasmaToolTips.Delay = cfg.workspace.tooltipDelay;
});
kcminputrc = (lib.mkIf (cfg.workspace.cursor != null && cfg.workspace.cursor.size != null) {
Mouse.cursorSize = cfg.workspace.cursor.size;
});
ksplashrc.KSplash = (lib.mkIf (cfg.workspace.splashScreen.theme != null) {
Engine = (if (cfg.workspace.splashScreen.engine == null) then
(splashScreenEngineDetect cfg.workspace.splashScreen.theme)
else cfg.workspace.splashScreen.engine);
Theme = cfg.workspace.splashScreen.theme;
});
kwinrc = (lib.mkIf (cfg.workspace.windowDecorations.theme != null) {
"org.kde.kdecoration2".library = cfg.workspace.windowDecorations.library;
"org.kde.kdecoration2".theme = cfg.workspace.windowDecorations.theme;
});
}
# We add persistence to some keys in order to not reset the themes on
# each generation when we use overrideConfig.
(lib.mkIf (cfg.overrideConfig && anyThemeSet) (
let
colorSchemeIgnore =
if (cfg.workspace.colorScheme != null || cfg.workspace.lookAndFeel != null) then
(import ../lib/colorscheme.nix {
inherit lib;
}) else { };
in
(lib.mkMerge
[
{
kcminputrc.Mouse.cursorTheme.persistent = lib.mkDefault (cfg.workspace.cursor != null && cfg.workspace.cursor.theme != null);
kdeglobals.General.ColorScheme.persistent = lib.mkDefault (cfg.workspace.colorScheme != null || cfg.workspace.lookAndFeel != null);
kdeglobals.Icons.Theme.persistent = lib.mkDefault (cfg.workspace.iconTheme != null);
kdeglobals.KDE.LookAndFeelPackage.persistent = lib.mkDefault (cfg.workspace.lookAndFeel != null);
plasmarc.Theme.name.persistent = lib.mkDefault (cfg.workspace.theme != null);
}
colorSchemeIgnore
])
))
]);
# We create a script which applies the different theme settings using
# kde tools. We then run this using an autostart script, where this is
# run only on the first login (unless overrideConfig is enabled),
# granted all the commands succeed (until we change the settings again).
programs.plasma.startup = {
startupScript."apply_themes" = (lib.mkIf anyThemeSet {
text = ''
${if cfg.workspace.lookAndFeel != null then "plasma-apply-lookandfeel -a ${cfg.workspace.lookAndFeel}" else ""}
${if cfg.workspace.theme != null then "plasma-apply-desktoptheme ${cfg.workspace.theme}" else ""}
${if (cfg.workspace.cursor != null && cfg.workspace.cursor.theme != null) then
"plasma-apply-cursortheme ${cfg.workspace.cursor.theme}" +
(if cfg.workspace.cursor.size != null then " --size ${builtins.toString cfg.workspace.cursor.size}" else "")
else ""}
${if cfg.workspace.colorScheme != null then "plasma-apply-colorscheme ${cfg.workspace.colorScheme}" else ""}
${if cfg.workspace.iconTheme != null then "${pkgs.kdePackages.plasma-workspace}/libexec/plasma-changeicons ${cfg.workspace.iconTheme}" else ""}
'';
priority = 1;
});
desktopScript."wallpaper_picture" = (lib.mkIf (cfg.workspace.wallpaper != null) {
# We just put this here as we need this script to be a desktop-script in
# order to link it together with the other desktop-script (namely
# panels). Adding a comment with the wallpaper makes it so that when the
# wallpaper changes, the sha256sum also changes for the js file, which
# gives us the correct behavior with last_run files.
text = "// Wallpaper to set later: ${cfg.workspace.wallpaper}";
postCommands = ''
plasma-apply-wallpaperimage ${cfg.workspace.wallpaper}
'';
priority = 3;
});
desktopScript."wallpaper_potd" = (lib.mkIf (cfg.workspace.wallpaperPictureOfTheDay != null) {
text = ''
// Wallpaper POTD
let allDesktops = desktops();
for (const desktop of allDesktops) {
desktop.wallpaperPlugin = "org.kde.potd";
desktop.currentConfigGroup = ["Wallpaper", "org.kde.potd", "General"];
desktop.writeConfig("Provider", "${cfg.workspace.wallpaperPictureOfTheDay.provider}");
desktop.writeConfig("UpdateOverMeteredConnection", "${if (cfg.workspace.wallpaperPictureOfTheDay.updateOverMeteredConnection) then "1" else "0"}");
${lib.optionalString (cfg.workspace.wallpaperFillMode != null) ''desktop.writeConfig("FillMode", "${cfg.workspace.wallpaperFillMode}");''}
}
'';
priority = 3;
});
desktopScript."wallpaper_plaincolor" = (lib.mkIf (cfg.workspace.wallpaperPlainColor != null) {
text = ''
// Wallpaper plain color
let allDesktops = desktops();
for (var desktopIndex = 0; desktopIndex < allDesktops.length; desktopIndex++) {
var desktop = allDesktops[desktopIndex];
desktop.wallpaperPlugin = "org.kde.color";
desktop.currentConfigGroup = Array("Wallpaper", "org.kde.color", "General");
desktop.writeConfig("Color", "${cfg.workspace.wallpaperPlainColor}");
}
'';
priority = 3;
});
desktopScript."wallpaper_slideshow" = (lib.mkIf (cfg.workspace.wallpaperSlideShow != null) {
text = ''
// Wallpaper slideshow
let allDesktops = desktops();
for (var desktopIndex = 0; desktopIndex < allDesktops.length; desktopIndex++) {
var desktop = allDesktops[desktopIndex];
desktop.wallpaperPlugin = "org.kde.slideshow";
desktop.currentConfigGroup = Array("Wallpaper", "org.kde.slideshow", "General");
desktop.writeConfig("SlidePaths", ${with cfg.workspace.wallpaperSlideShow; if ((builtins.isPath path) || (builtins.isString path)) then
"\"" + (builtins.toString path) + "\"" else
"[" + (builtins.concatStringsSep "," (map (s: "\"" + s + "\"") path)) + "]"});
desktop.writeConfig("SlideInterval", "${builtins.toString cfg.workspace.wallpaperSlideShow.interval}");
${lib.optionalString (cfg.workspace.wallpaperFillMode != null) ''desktop.writeConfig("FillMode", "${cfg.workspace.wallpaperFillMode}");''}
}
'';
priority = 3;
});
};
});
}