{ pkgs, ... }: let update_time = "10m"; backgrounds_directory = "$HOME/Immagini/Sfondi/1080+/1440+"; update_script = pkgs.writeShellScriptBin "wl-update-background" '' set -e if [ $# -eq 0 ]; then image=`${pkgs.findutils}/bin/find ${backgrounds_directory} -type f | ${pkgs.gnugrep}/bin/grep -v "/\." | ${pkgs.coreutils}/bin/shuf -n 1` else image="$1" fi echo "image: $image" ${pkgs.swww}/bin/swww img "$image" ''; in { home.packages = [ update_script ]; systemd.user.services."wl-update-background" = { Unit = { Description = "Set random desktop background using swww"; After = [ "graphical-session.pre.target" ]; PartOf = [ "graphical-session.target" ]; RequiresMountsFor = [ "/home/bertof/Immagini" ]; }; Install = { WantedBy = [ "graphical-session.target" ]; }; Service = { Type = "oneshot"; IOSchedulingClass = "idle"; ExecStart = "${update_script}/bin/wl-update-background"; }; }; systemd.user.timers."wl-update-background" = { Unit = { Description = "Set random desktop background using swww"; }; Timer = { OnUnitActiveSec = update_time; }; Install = { WantedBy = [ "timers.target" ]; }; }; }