64 lines
1.8 KiB
Nix

{
pkgs,
lib,
...
}:
with lib; let
# load the wallpapers from the wallpapers directory - this gives a set with the folder content
dirContent = builtins.readDir ../../../wallpapers;
wallpaperString = lib.strings.concatMapStrings (x: " " + x) wallpapers;
# # load each wallpaper and keep its path (now in the nix store) as an array
# wallpapers = map (x: builtins.readDir "${../../../wallpapers}/${x.value}") dirContent;
# wallpaperString = lib.strings.concatMapStrings (x: " " + x) wallpapers;
# script that picks a random wallpaper from the array and sets it as the desktop background
monitor = ""; # leave empty to set the wallpaper on all monitors
wallpaperRandomizer = pkgs.writeShellScriptBin "wallpaperRandomizer" ''
wallpaper=$(shuf -n 1 -e ${wallpaperString})
hyprctl hyprpaper unload all
hyprctl hyprpaper preload $wallpaper
hyprctl hyprpaper wallpaper "${monitor},$wallpaper"
'';
in {
home.packages = [wallpaperRandomizer];
services.hyprpaper = {
enable = true;
settings = {
ipc = "off";
splash = false;
};
};
systemd.user = {
services.wallpaperRandomizer = {
Install = {WantedBy = ["graphical-session.target"];};
Unit = {
Description = "Set random desktop background using hyprpaper";
After = ["graphical-session-pre.target"];
PartOf = ["graphical-session.target"];
};
Service = {
Type = "oneshot";
ExecStart = "${wallpaperRandomizer}/bin/wallpaperRandomizer";
IOSchedulingClass = "idle";
};
};
timers.wallpaperRandomizer = {
Unit = {Description = "Set random desktop background using hyprpaper on an interval";};
Timer = {OnUnitActiveSec = "6h";};
Install = {WantedBy = ["timers.target"];};
};
};
}