diff --git a/home/sam/common/optional/desktop/wallpaper-changer/swww-wallpaper-changer/default.nix b/home/sam/common/optional/desktop/wallpaper-changer/swww-wallpaper-changer/default.nix index 2cb0e0c..6f9951f 100644 --- a/home/sam/common/optional/desktop/wallpaper-changer/swww-wallpaper-changer/default.nix +++ b/home/sam/common/optional/desktop/wallpaper-changer/swww-wallpaper-changer/default.nix @@ -1,15 +1,53 @@ -{ pkgs, ... }: -let - scripts = { - swww-wallpaper-changer = pkgs.writeShellApplication { - name = "swww-wallpaper-changer"; - text = builtins.readFile ./swww-wallpaper-changer.sh; +{ + pkgs, + ... +}: +{ + systemd.user.services.wallpaper-changer = { + Unit = { + Description = "Script to change wallpaper using swww"; + After = [ "graphical-session.target" ]; # or "wayland.target", depending on your system setup + #After = [ "hyprland-session.target" ]; + }; + Install = { + WantedBy = [ "default.target" ]; + }; + Service = { + Restart = "on-failure"; # This will make the service restart on failure + ExecStart= "${pkgs.writeShellScript "swww-daemon" '' + ${pkgs.swww}/bin/swww-daemon + ''}"; + ExecStartPost = "${pkgs.writeShellScript "swww-wallpaper-changer" '' + #!/run/current-system/sw/bin/bash + 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/" + + swww_daemon_pid=$(pidof -x 'swww-daemon') + swww_pid=$(pidof -x 'swww') + + #[ -z "$swww_daemon_pid" ] || kill -15 "$swww_daemon_pid" + [ -z "$swww_pid" ] || kill -15 "$swww_pid" + #${pkgs.swww}/bin/swww-daemon & + + 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 + ${pkgs.swww}/bin/swww img "$file" --transition-step 10 --transition-fps 60 + [ $? != 0 ] && echo "swww failed. Exiting" && exit 1 + sleep 3 + done + done + ''}"; }; }; -in -{ - home.packages = builtins.attrValues { - inherit (scripts) - swww-wallpaper-changer; - }; } diff --git a/hosts/nixdev/default.nix b/hosts/nixdev/default.nix index 3ddc1ba..e410bec 100644 --- a/hosts/nixdev/default.nix +++ b/hosts/nixdev/default.nix @@ -70,7 +70,7 @@ # sddm # sshfs-fuse # wdisplays - wallpaper_changer + #wallpaper_changer # #(callPackage ../../nixos_modules/themes/sddm-sugar-candy.nix{}).sddm-sugar-candy-theme # libsForQt5.qt5.qtgraphicaleffects #required for sugar candy # #(import ../../nixos_modules/scripts/wallpaper_changer.nix { inherit pkgs; }) diff --git a/result b/result deleted file mode 120000 index 26cdee6..0000000 --- a/result +++ /dev/null @@ -1 +0,0 @@ -/nix/store/iil5ayx17m3dn8jqrrv5y48prrcxb7d8-sddm-sugar-candy-theme-1.6 \ No newline at end of file