From f0c302ac499c04113d9aaa55af33e49cf0a03527 Mon Sep 17 00:00:00 2001 From: moons14 Date: Wed, 29 Oct 2025 21:13:44 +0900 Subject: [PATCH] fix error --- modules/home/wallpaper/default.nix | 51 ++++++++++++++----------- modules/home/wallpaper/set-wallpaper.sh | 18 --------- modules/home/wallpaper/swww.sh | 11 ++++++ 3 files changed, 39 insertions(+), 41 deletions(-) delete mode 100644 modules/home/wallpaper/set-wallpaper.sh create mode 100644 modules/home/wallpaper/swww.sh diff --git a/modules/home/wallpaper/default.nix b/modules/home/wallpaper/default.nix index 232a10f..dead343 100644 --- a/modules/home/wallpaper/default.nix +++ b/modules/home/wallpaper/default.nix @@ -6,61 +6,66 @@ let rev = "40912e6418737e93b59a38bcf189270cbf26656d"; hash = "sha256-1QR3J+wgLVNjucPSVELv0FicNt+jM2KPLU5ubBfxjHI="; }; + + swwwScript = ./swww.sh; in { home.file."wallpapers" = { source = walls; recursive = true; }; - home.file.".local/bin/set-wallpaper.sh" = { - source = ./set-wallpaper.sh; + home.packages = with pkgs; [ + swww + ]; + + home.file.".config/swww/swww.sh" = { + source = swwwScript; executable = true; }; - home.packages = with pkgs; [ - swww - bash - findutils - coreutils - ]; - - systemd.user.services.swww = { + systemd.user.services."swww-daemon" = { Unit = { - Description = "swww init (Wayland wallpaper daemon)"; + Description = "SWWW daemon"; After = [ "graphical-session.target" ]; + PartOf = [ "graphical-session.target" ]; }; Service = { - ExecStart = [ "${pkgs.swww}/bin/swww" "init" ]; + Type = "simple"; + Environment = [ + "PATH=${lib.makeBinPath [ pkgs.swww pkgs.coreutils pkgs.findutils pkgs.bash ]}:$PATH" + ]; + ExecStart = "${pkgs.bash}/bin/bash -lc 'if swww query >/dev/null 2>&1; then exit 0; else exec swww-daemon -f xrgb; fi'"; Restart = "on-failure"; + RestartSec = 2; }; Install = { WantedBy = [ "graphical-session.target" ]; }; }; - systemd.user.services."wallpaper-rotate" = { + systemd.user.services."change-wallpaper" = { Unit = { - Description = "Rotate wallpaper via swww"; - After = [ "swww.service" "graphical-session.target" ]; - Wants = [ "swww.service" ]; + Description = "Set/rotate wallpaper via swww"; + After = [ "swww-daemon.service" "graphical-session.target" ]; }; Service = { Type = "oneshot"; - ExecStart = [ "${pkgs.bash}/bin/bash" "/home/moons/.local/bin/set-wallpaper.sh" ]; + Environment = [ + "PATH=${lib.makeBinPath [ pkgs.swww pkgs.coreutils pkgs.findutils pkgs.bash ]}:$PATH" + ]; + ExecStart = "${pkgs.bash}/bin/bash -lc '$HOME/.config/swww/swww.sh'"; }; Install = { - WantedBy = [ "default.target" ]; + WantedBy = [ "graphical-session.target" ]; }; }; - systemd.user.timers."wallpaper-rotate" = { + systemd.user.timers."change-wallpaper" = { Unit = { - Description = "Change wallpaper every 1 minute"; + Description = "Timer to change wallpapers every hour"; }; Timer = { - OnBootSec = "30s"; - OnUnitActiveSec = "1min"; - Unit = "wallpaper-rotate.service"; + OnCalendar = "hourly"; Persistent = true; }; Install = { diff --git a/modules/home/wallpaper/set-wallpaper.sh b/modules/home/wallpaper/set-wallpaper.sh deleted file mode 100644 index ddc1129..0000000 --- a/modules/home/wallpaper/set-wallpaper.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/env bash -# set-wallpaper.sh -set -euo pipefail - -WALLS="${HOME}/wallpapers" - -if ! swww query >/dev/null 2>&1; then - swww init -fi - -mapfile -t files < <(find "$WALLS" -type f \( -iname '*.jpg' -o -iname '*.jpeg' -o -iname '*.png' -o -iname '*.webp' \)) - - -[[ ${#files[@]} -gt 0 ]] || exit 0 - -pick="${files[RANDOM % ${#files[@]}]}" - -exec swww img "$pick" --transition-type any --transition-step 90 --transition-fps 60 diff --git a/modules/home/wallpaper/swww.sh b/modules/home/wallpaper/swww.sh new file mode 100644 index 0000000..a93d374 --- /dev/null +++ b/modules/home/wallpaper/swww.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +WALLPAPERS_DIR="${HOME}/wallpapers" + +mapfile -t files < <(find "$WALLPAPERS_DIR" -type f 2>/dev/null) +[ "${#files[@]}" -eq 0 ] && exit 0 + +file="$(printf '%s\n' "${files[@]}" | shuf -n 1)" + + +exec swww img "$file" --transition-type grow --transition-step 90