Not an ideal solution but a workaround.
Variety doesnt seem to return when calling set. So we must finish it manually instead, for example, using a timeout. The following script sets the wallpaper and then waits 10minutes before killing variety.
#! /usr/bin/env nix-shell
#! nix-shell -i bash -p bash
RANDOM_FILE=$(find "$BACKGROUNDS" -type f | shuf -n 1 | tr -d '\n')
variety --set="$RANDOM_FILE" &
sleep 10m
kill $!
After killing the script, you can let systemd restart it by passing restart=always, thus changing the wallpaper every time it dies:
systemd.user.services = {
wallpaper-slideshow-random = {
Unit = {
Description = "Sets up the wallpaper slideshow randomly";
};
Install = {
WantedBy = [ "default.target" ];
};
Service = {
Type = "exec";
ExecStart = "${pkgs.writeShellApplication
{ name = "wallpaper-slideshow-random";
# runtimeInputs = [pkgs.variety ];
text = builtins.readFile ./scripts/random_wallpaper.sh;}
}/bin/wallpaper-slideshow-random";
Restart = "always";
Environment = [
"BACKGROUNDS=${config.home.sessionVariables.BACKGROUNDS}"
];
};
};
};
There should be a way of killing and restarting from bash. But i found no success
(the timeout utility seems to kill the whole script).