wallpaper-changer systemd service - working

This commit is contained in:
Sam 2024-05-12 12:35:31 +01:00
parent 03495183b2
commit be4163dcd4
2 changed files with 12 additions and 29 deletions

View File

@ -8,10 +8,10 @@
imports = [ imports = [
../wallpaper-changer/swww-wallpaper-changer ../wallpaper-changer/swww-wallpaper-changer
]; ];
wayland.windowManager.hyprland = { wayland.windowManager.hyprland = {
enable = true; enable = true;
systemd = { systemd = {
variables = ["--all"];
enable = true; enable = true;
# Same as default, but stop graphical-session too # Same as default, but stop graphical-session too
extraCommands = lib.mkBefore [ extraCommands = lib.mkBefore [

View File

@ -6,45 +6,28 @@
systemd.user.services.wallpaper-changer = { systemd.user.services.wallpaper-changer = {
Unit = { Unit = {
Description = "Script to change wallpaper using swww"; Description = "Script to change wallpaper using swww";
After = [ "graphical-session.target" ]; # or "wayland.target", depending on your system setup PartOf = [ "hyprland-session.target" ];
#After = [ "hyprland-session.target" ]; After = [ "hyprland-session.target" ]; # or "wayland.target", depending on your system setup
}; };
Install = { Install = {
WantedBy = [ "default.target" ]; WantedBy = [ "default.target" ];
}; };
Service = { Service = {
Restart = "on-failure"; # This will make the service restart on failure Type = [ "oneshot" ];
ExecStart= "${pkgs.writeShellScript "swww-daemon" '' ExecStart = "${pkgs.writeShellScript "swww-wallpaper-changer" ''
${pkgs.swww}/bin/swww-daemon
''}";
ExecStartPost = "${pkgs.writeShellScript "swww-wallpaper-changer" ''
#!/run/current-system/sw/bin/bash
export WAYLAND_DISPLAY="wayland-1" export WAYLAND_DISPLAY="wayland-1"
set +o errexit
set +o nounset
set +o pipefail
script_name=''${BASH_SOURCE[0]}
for pid in $(pidof -x "$script_name"); do
if [ "$pid" != $$ ]; then
kill -15 "$pid"
fi
done
#[ "$XDG_SESSION_TYPE" != "wayland" ] && echo "Not a Wayland session, exiting." && exit 1
wallpaper_dir="$HOME/.local/share/bg/" wallpaper_dir="$HOME/.local/share/bg/"
swww_daemon_pid=$(pidof -x 'swww-daemon') # Allow some time for desktop to start
swww_pid=$(pidof -x 'swww') sleep 3
echo "starting daemon..."
#[ -z "$swww_daemon_pid" ] || kill -15 "$swww_daemon_pid" ${pkgs.swww}/bin/swww-daemon &
[ -z "$swww_pid" ] || kill -15 "$swww_pid"
#${pkgs.swww}/bin/swww-daemon &
while true; do while true; do
find "$wallpaper_dir" -type f -follow \( -iname \*.jpg -o -iname \*.png -o -iname \*.gif -o -iname \*.bmp \) | shuf | while read -r file; do find "$wallpaper_dir" -type f -follow \( -iname \*.jpg -o -iname \*.png -o -iname \*.gif -o -iname \*.bmp \) | shuf | while read -r file; do
${pkgs.swww}/bin/swww img "$file" --transition-step 10 --transition-fps 60 ${pkgs.swww}/bin/swww img "$file" --transition-step 10 --transition-fps 60
[ $? != 0 ] && echo "swww failed. Exiting" && exit 1 [ $? != 0 ] && echo "swww failed, reloading daemon" && exit 1
sleep 3 sleep 600
done done
done done
''}"; ''}";