forked from djpohly/dwl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
derivation.nix
361 lines (288 loc) · 9.34 KB
/
derivation.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
{ lib, pkgs, stdenv, wayland, conf ? null, inputs, ... }:
let
prefix = "${pkgs.writeShellScriptBin "prefix" ''
prefix="$1"; shift
echo "$prefix: Starting: $@"
exec "$@" > >(sed "s/^/$prefix: /") 2> >(sed "s/^/ERR: $prefix /" >&2)
''}/bin/prefix";
cleanup = "${pkgs.writeShellScriptBin "cleanup" ''
function stop() {
killall -u "$USER" -w "$1" >/dev/null 2>&1
}
stop swayidle
stop swaync
stop waybar
stop udiskie
stop firefox
stop slack
stop spotify
stop sway-audio-idle-inhibit
stop mpvpaper
stop wob
stop playerctld
stop wayvnc
stop dwlstartup
''}/bin/cleanup";
waybar = "${pkgs.callPackage ./waybar { inherit pkgs inputs; }}/bin/waybar-wrapped";
swipeguess = (pkgs.callPackage ./swipeguess { inherit pkgs inputs; });
swaync = "${pkgs.writeShellApplication {
name = "swaync-wrapped";
runtimeInputs = [ pkgs.swaynotificationcenter ];
text = ''
export XDG_CONFIG_DIRS="${pkgs.swaynotificationcenter}/etc/xdg:$XDG_CONFIG_DIRS"
exec swaync \
-s ${./swaync/style.css} \
-c ${./swaync/config.json}
'';
}}/bin/swaync-wrapped";
# A helper script to show an application menu
appmenu = (pkgs.writeShellScriptBin "appmenu" ''
exec "${pkgs.nwg-drawer}/bin/nwg-drawer"
''
);
# A helper script to toggle, show or hide an on screen keyboard
wvkbd = inputs.wvkbd-minego.packages.${pkgs.system}.default;
osk = (pkgs.writeShellScriptBin "osk" ''
case $1 in
help|usage|-h|--help)
echo "osk show|hide|toggle"
;;
show)
${wvkbd}/bin/wvkbd-minego -O | ${swipeguess}/bin/swipeGuess ${./words.txt} | ${swipeguess}/bin/completelyTypeWord.sh & disown
;;
hide)
pkill -x wvkbd-minego
;;
toggle|*)
if pgrep -x wvkbd-minego ; then
osk hide
else
osk show
fi
;;
esac
''
);
# A helper script used by DWL to control the backlight
backlight = (pkgs.writeShellScriptBin "backlight" ''
function osd() {
float=$(${pkgs.light}/bin/light -G)
value=''${float%.*}
if [ "$value" -gt 100 ]; then
value=100
fi
if [[ -v WOBSOCK ]]; then
echo "$value" > "$WOBSOCK"
fi
}
case "$1" in
osd)
osd
;;
up|plus)
${pkgs.light}/bin/light -A 5
$0 osd
;;
down|minus)
${pkgs.light}/bin/light -U 5
$0 osd
;;
set)
${pkgs.light}/bin/light -S $2
;;
get|*)
${pkgs.light}/bin/light -G
;;
esac
'');
mediacontrol = (pkgs.writeShellScriptBin "mediacontrol" ''
# Read the last active player, which is set when a command is done while
# something is actually playing. If nothing is playing now then the most recent
# thing that was playing should be activated again.
ACTIVE_PLAYER=`cat ~/.mediacontrol-last-player.txt 2>/dev/null`
# Check to see if anything is playing now. If so, that player will be controlled
while IFS= read -r PLAYER; do
STATE=`${pkgs.playerctl}/bin/playerctl -p "$PLAYER" status`
# echo "$$ Player: $PLAYER: $STATE"
case $STATE in
Playing)
ACTIVE_PLAYER=$PLAYER
echo "$ACTIVE_PLAYER" > ~/.mediacontrol-last-player.txt
;;
*|Paused)
;;
esac
done < <(${pkgs.playerctl}/bin/playerctl -l)
function showvolume() {
VOL=`${pkgs.pamixer}/bin/pamixer --get-volume`
if [ $VOL -gt 100 ]; then
VOL=100
fi
if [[ -v WOBSOCK ]]; then
echo $VOL > $WOBSOCK
fi
}
case $1 in
next)
${pkgs.playerctl}/bin/playerctl -p "$ACTIVE_PLAYER" next
;;
prev)
${pkgs.playerctl}/bin/playerctl -p "$ACTIVE_PLAYER" previous
;;
toggle)
${pkgs.playerctl}/bin/playerctl -p "$ACTIVE_PLAYER" play-pause
;;
pause)
${pkgs.playerctl}/bin/playerctl pause -a
;;
what)
STATE=`${pkgs.playerctl}/bin/playerctl -p "$ACTIVE_PLAYER" status`
case $STATE in
Playing)
ARTIST=`${pkgs.playerctl}/bin/playerctl -p "$ACTIVE_PLAYER" metadata artist`
TITLE=`${pkgs.playerctl}/bin/playerctl -p "$ACTIVE_PLAYER" metadata title`
echo " $TITLE BY $ARTIST"
;;
Paused)
echo
;;
*)
;;
esac
;;
status)
${pkgs.playerctl}/bin/playerctl -p "$ACTIVE_PLAYER" $@
case $STATE in
Playing)
exit 0
;;
*)
exit 1
;;
esac
;;
up)
${pkgs.pamixer}/bin/pamixer --increase 5
showvolume
;;
down)
${pkgs.pamixer}/bin/pamixer --decrease 5
showvolume
;;
mute)
${pkgs.pamixer}/bin/pamixer --toggle-mute
${pkgs.pamixer}/bin/pamixer --get-mute | grep "true" > /dev/null
showvolume
;;
micmute)
${pkgs.pamixer}/bin/pamixer --default-source --toggle-mute
${pkgs.pamixer}/bin/pamixer --default-source --get-mute | grep "true" > /dev/null
showvolume
;;
*)
${pkgs.playerctl}/bin/playerctl -p "$ACTIVE_PLAYER" $@
;;
esac
exit $?
'');
wlr-power = (pkgs.writeShellScriptBin "wlr-power" ''
case "$1" in
on|off|toggle)
${pkgs.wlr-randr}/bin/wlr-randr --json | ${pkgs.jq}/bin/jq -r '.[].name' | \
xargs -I {} ${pkgs.wlr-randr}/bin/wlr-randr --output {} --$1
;;
*)
echo "Usage: $0 <on|off|toggle>"
;;
esac
'');
swayidle = "${pkgs.swayidle}/bin/swayidle";
swaylock = "${pkgs.swaylock-effects}/bin/swaylock";
wob = "${pkgs.wob}/bin/wob";
playerctld = "${pkgs.playerctl}/bin/playerctld";
playerctl = "${pkgs.playerctl}/bin/playerctl";
udiskie = "${pkgs.udiskie}/bin/udiskie";
firefox = "${pkgs.firefox}/bin/firefox";
idle-inhibit= "${pkgs.sway-audio-idle-inhibit}/bin/sway-audio-idle-inhibit";
mpvpaper = "${pkgs.mpvpaper}/bin/mpvpaper";
wayvnc = "${pkgs.wayvnc}/bin/wayvnc";
authagent = "${pkgs.polkit_gnome}/libexec/polkit-gnome-authentication-agent-1";
dwlstartup = (pkgs.writeShellScriptBin "dwlstartup" ''
# Cleanup any old status
rm -rf ~/.cache/dwl 2>/dev/null
${./waybar/dwl-status} reset
(
${prefix} SWAYIDLE ${swayidle} -w \
timeout 180 '${swaylock} -d -F -c 000000 -f' \
timeout 195 'wlr-power off' \
resume 'wlr-power on' \
before-sleep '${swaylock} -F -d -c 000000 -f' &
(tail -f "$WOBSOCK" | ${prefix} WOB ${wob}) &
# waybar requires playerctld, so thart that first
${prefix} PLAYERCTLD ${playerctld} &
sleep 2
${prefix} WAYBAR ${waybar} &
${prefix} SWAYNC ${swaync} &
${prefix} UDISKIE ${udiskie} --tray &
# ${prefix} FIREFOX ${firefox} &
if command -v slack &> /dev/null; then
${prefix} SLACK slack &
fi
if command -v spotify &> /dev/null; then
${prefix} SPOTIFY spotify &
fi
${prefix} IDLE-INHIBIT ${idle-inhibit} &
${prefix} MPVPAPER ${mpvpaper} -n 100 '*' ~/Pictures/wallpaper.mp4 -o "--no-keepaspect" > /dev/null 2>&1 &
${prefix} WAYVNC ${wayvnc} &
${prefix} POLKIT ${authagent} &
systemctl --user restart xdg-desktop-portal.service
) &
exec ${./waybar/dwl-status} monitor
'');
dwl-wrapped = (pkgs.writeShellScriptBin "dwl" ''
${cleanup}
export XDG_CURRENT_DESKTOP=wlroots
eval "$(${pkgs.openssh}/bin/ssh-agent -k)"
eval "$(${pkgs.openssh}/bin/ssh-agent)"
ln -sf "$SSH_AUTH_SOCK" ~/.ssh/ssh_auth_sock
export SSH_AUTH_SOCK=~/.ssh/ssh_auth_sock
export SSH_AENT_PID
export MOZ_ENABLE_WAYLAND=1
export QT_QPA_PLATFORM=wayland-egl
export GDK_BACKEND=wayland
export GDK_SCALE=1
export CLUTTER_BACKEND=wayland
export WOBSOCK="$XDG_RUNTIME_DIR/wob.sock"
rm -f "$WOBSOCK" && mkfifo "$WOBSOCK"
${pkgs.dbus}/bin/dbus-run-session -- ${pkgs.dwl-unwrapped}/bin/dwl -s ${dwlstartup}/bin/dwlstartup > ~/.cache/dwl.out 2>&1
${cleanup}
pkill -P $$
'');
startw = (pkgs.writeShellScriptBin "startw" ''
exec ${dwl-wrapped}/bin/dwl
'');
in
pkgs.symlinkJoin {
name = "dwl-wrapped";
paths = [
# Our wrapper for starting dwl
dwl-wrapped
# Helper scripts that our dwl config uses
startw
appmenu
backlight
mediacontrol
osk
pkgs.swaylock
wlr-power
# wtype is used by swipeguess to type the word
pkgs.wtype
# The original DWL package, for everything except the binary
pkgs.dwl-unwrapped
# Other tools that my DWL config depends on
pkgs.wlr-randr
pkgs.swaynotificationcenter
];
} // {
passthru.providedSessions = [ "dwl" ];
}