/
wlogout.nix
148 lines (124 loc) · 3.75 KB
/
wlogout.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
{ config, lib, pkgs, ... }:
let
inherit (lib) all filterAttrs isStorePath literalExpression types;
inherit (lib.options) mkEnableOption mkPackageOption mkOption;
inherit (lib.modules) mkIf;
inherit (lib.strings) concatMapStrings;
inherit (builtins) toJSON;
cfg = config.programs.wlogout;
jsonFormat = pkgs.formats.json { };
wlogoutLayoutConfig = with types;
submodule {
freeformType = jsonFormat.type;
options = {
label = mkOption {
type = str;
default = "";
example = "shutdown";
description = "CSS label of button.";
};
action = mkOption {
type = either path str;
default = "";
example = "systemctl poweroff";
description = "Command to execute when clicked.";
};
text = mkOption {
type = str;
default = "";
example = "Shutdown";
description = "Text displayed on button.";
};
keybind = mkOption {
type = str;
default = "";
example = "s";
description = "Keyboard character to trigger this action.";
};
height = mkOption {
type = nullOr (numbers.between 0 1);
default = null;
example = 0.5;
description = "Relative height of tile.";
};
width = mkOption {
type = nullOr (numbers.between 0 1);
default = null;
example = 0.5;
description = "Relative width of tile.";
};
circular = mkOption {
type = nullOr bool;
default = null;
example = true;
description = "Make button circular.";
};
};
};
in {
meta.maintainers = [ lib.maintainers.Scrumplex ];
options.programs.wlogout = with lib.types; {
enable = mkEnableOption "wlogout";
package = mkPackageOption pkgs "wlogout" { };
layout = mkOption {
type = listOf wlogoutLayoutConfig;
default = [ ];
description = ''
Layout configuration for wlogout, see <https://github.com/ArtsyMacaw/wlogout#config>
for supported values.
'';
example = literalExpression ''
[
{
label = "shutdown";
action = "systemctl poweroff";
text = "Shutdown";
keybind = "s";
}
]
'';
};
style = mkOption {
type = nullOr (either path str);
default = null;
description = ''
CSS style of the bar.
See <https://github.com/ArtsyMacaw/wlogout#style>
for the documentation.
If the value is set to a path literal, then the path will be used as the css file.
'';
example = ''
window {
background: #16191C;
}
button {
color: #AAB2BF;
}
'';
};
};
config = let
# Removes nulls because wlogout ignores them.
# This is not recursive.
removeTopLevelNulls = filterAttrs (_: v: v != null);
cleanJSON = foo: toJSON (removeTopLevelNulls foo);
# wlogout doesn't want a JSON array, it just wants a list of JSON objects
layoutJsons = map cleanJSON cfg.layout;
layoutContent = concatMapStrings (l: l + "\n") layoutJsons;
in mkIf cfg.enable {
assertions = [
(lib.hm.assertions.assertPlatform "programs.wlogout" pkgs
lib.platforms.linux)
];
home.packages = [ cfg.package ];
xdg.configFile."wlogout/layout" = mkIf (cfg.layout != [ ]) {
source = pkgs.writeText "wlogout/layout" layoutContent;
};
xdg.configFile."wlogout/style.css" = mkIf (cfg.style != null) {
source = if builtins.isPath cfg.style || isStorePath cfg.style then
cfg.style
else
pkgs.writeText "wlogout/style.css" cfg.style;
};
};
}