diff --git a/modules/home/wallpaper.nix b/modules/home/wallpaper.nix deleted file mode 100644 index 1823b19..0000000 --- a/modules/home/wallpaper.nix +++ /dev/null @@ -1,14 +0,0 @@ -{ pkgs, lib, ... }: -let - walls = pkgs.fetchFromGitHub { - owner = "orangci"; - repo = "walls-catppuccin-mocha"; - rev = "40912e6418737e93b59a38bcf189270cbf26656d"; - hash = "sha256-1QR3J+wgLVNjucPSVELv0FicNt+jM2KPLU5ubBfxjHI="; # nix-shell -p nix-prefetch-github --run 'nix-prefetch-github orangci walls-catppuccin-mocha --rev 40912e6418737e93b59a38bcf189270cbf26656d' - }; -in { - home.file."wallpapers" = { - source = walls; - recursive = true; - }; -} diff --git a/modules/home/wallpaper/default.nix b/modules/home/wallpaper/default.nix new file mode 100644 index 0000000..a906b53 --- /dev/null +++ b/modules/home/wallpaper/default.nix @@ -0,0 +1,70 @@ +{ pkgs, lib, ... }: +let + walls = pkgs.fetchFromGitHub { + owner = "orangci"; + repo = "walls-catppuccin-mocha"; + rev = "40912e6418737e93b59a38bcf189270cbf26656d"; + hash = "sha256-1QR3J+wgLVNjucPSVELv0FicNt+jM2KPLU5ubBfxjHI="; + }; +in { + home.file."wallpapers" = { + source = walls; + recursive = true; + }; + + home.file.".local/bin/set-wallpaper.sh" = { + source = ./set-wallpaper.sh; + executable = true; + }; + + home.packages = with pkgs; [ + swww + bash + findutils + coreutils + ]; + + systemd.user.services.swww = { + Unit = { + Description = "swww daemon"; + After = [ "graphical-session.target" ]; + }; + Service = { + ExecStart = "${pkgs.swww}/bin/swww-daemon"; + Restart = "on-failure"; + }; + Install = { + WantedBy = [ "graphical-session.target" ]; + }; + }; + + systemd.user.services."wallpaper-rotate" = { + Unit = { + Description = "Rotate wallpaper via swww"; + After = [ "swww.service" "graphical-session.target" ]; + Wants = [ "swww.service" ]; + }; + Service = { + Type = "oneshot"; + ExecStart = "${pkgs.bash}/bin/bash -lc $HOME/.local/bin/set-wallpaper.sh"; + }; + Install = { + WantedBy = [ "default.target" ]; + }; + }; + + systemd.user.timers."wallpaper-rotate" = { + Unit = { + Description = "Change wallpaper every 1 minute"; + }; + Timer = { + OnBootSec = "30s"; + OnUnitActiveSec = "1min"; + Unit = "wallpaper-rotate.service"; + Persistent = true; + }; + Install = { + WantedBy = [ "timers.target" ]; + }; + }; +} diff --git a/modules/home/wallpaper/set-wallpaper.sh b/modules/home/wallpaper/set-wallpaper.sh new file mode 100644 index 0000000..0d68b97 --- /dev/null +++ b/modules/home/wallpaper/set-wallpaper.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash +# set-wallpaper.sh +set -euo pipefail + +WALLS="${HOME}/wallpapers" + +# Pick up wallpaper(jpg/jpeg/png/webp) +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/profiles/gui.nix b/profiles/gui.nix index f3ef404..b54e283 100644 --- a/profiles/gui.nix +++ b/profiles/gui.nix @@ -16,6 +16,6 @@ ./../modules/home/noctalia.nix ./../modules/home/avatar.nix ./../modules/home/ghostty - ./../modules/home/wallpaper.nix + ./../modules/home/wallpaper ]; } \ No newline at end of file