forked from
lass.pds.lassul.us/superconfig
This repository has no description
1.4 kB
35 lines
1{
2 perSystem =
3 { pkgs, ... }:
4 {
5 packages.lockscreen =
6 (pkgs.writeShellApplication {
7 name = "lockscreen";
8 runtimeInputs = [
9 pkgs.ffmpeg
10 pkgs.coreutils
11 pkgs.procps
12 pkgs.swaylock-plugin
13 pkgs.mpvpaper
14 ];
15 text = ''
16 # Random lock background (video or image) from the shared
17 # ~/wallpaper folder. Falls back to a plain locker when the
18 # folder is empty, so the screen still locks.
19 FILE=$(find "$HOME/wallpaper" -type f \( \
20 -iname '*.mp4' -o -iname '*.webm' -o -iname '*.mkv' -o -iname '*.mov' -o \
21 -iname '*.jpg' -o -iname '*.jpeg' -o -iname '*.png' -o -iname '*.gif' -o -iname '*.webp' \
22 \) 2>/dev/null | shuf -n 1 || true)
23 if [ -z "$FILE" ]; then
24 exec swaylock-plugin "$@"
25 fi
26 DUR=$(ffprobe -v error -show_entries format=duration -of csv=p=0 "$FILE" 2>/dev/null | cut -d. -f1)
27 case "$DUR" in "" | *[!0-9]*) DUR=1 ;; esac
28 if [ "$DUR" -lt 1 ]; then DUR=1; fi
29 START=$((RANDOM % DUR))
30 exec swaylock-plugin --command "mpvpaper -o \"no-audio loop start=$START\" '*' \"$FILE\"" "$@"
31 '';
32 }).overrideAttrs
33 { passthru.usage = builtins.readFile ./usage.kdl; };
34 };
35}