2025-03-11 15:38:44 +01:00

67 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;
# only keep regular (the true files) as a list
# loop over the set and keep the values where the key is "regular"
wallpapersIntermediate = attrsToList dirContent;
# remove the attr, keep the value
wallpapers = map (x: x.value) wallpapersIntermediate;
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"];};
};
};
}