wallpaper-changer systemd service

This commit is contained in:
Sam 2024-05-12 11:09:46 +01:00
parent 67c39715ce
commit 03495183b2
3 changed files with 51 additions and 14 deletions

View File

@ -1,15 +1,53 @@
{ pkgs, ... }:
let
scripts = {
swww-wallpaper-changer = pkgs.writeShellApplication {
name = "swww-wallpaper-changer";
text = builtins.readFile ./swww-wallpaper-changer.sh;
};
};
in
{ {
home.packages = builtins.attrValues { pkgs,
inherit (scripts) ...
swww-wallpaper-changer; }:
{
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
''}";
};
}; };
} }

View File

@ -70,7 +70,7 @@
# sddm # sddm
# sshfs-fuse # sshfs-fuse
# wdisplays # wdisplays
wallpaper_changer #wallpaper_changer
# #(callPackage ../../nixos_modules/themes/sddm-sugar-candy.nix{}).sddm-sugar-candy-theme # #(callPackage ../../nixos_modules/themes/sddm-sugar-candy.nix{}).sddm-sugar-candy-theme
# libsForQt5.qt5.qtgraphicaleffects #required for sugar candy # libsForQt5.qt5.qtgraphicaleffects #required for sugar candy
# #(import ../../nixos_modules/scripts/wallpaper_changer.nix { inherit pkgs; }) # #(import ../../nixos_modules/scripts/wallpaper_changer.nix { inherit pkgs; })

1
result
View File

@ -1 +0,0 @@
/nix/store/iil5ayx17m3dn8jqrrv5y48prrcxb7d8-sddm-sugar-candy-theme-1.6