nix-configs/modules/desktop/wpaperd.nix
Lucy Hochkamp 33ee2f5760
Some checks failed
ci/woodpecker/push/build-cache Pipeline failed
ci/woodpecker/cron/dependency-pr Pipeline was successful
meow
2025-10-16 12:18:36 +02:00

85 lines
2.7 KiB
Nix

{
pkgs,
config,
lib,
...
}:
let
cfg = config.xyno.desktop.wpaperd;
# wpaperdConf = pkgs.writeText "wpaperd.conf" ''
# [default]
# path = "/home/${config.xyno.system.user.name}/Pictures/backgrounds"
# duration = "10m"
# sorting = "random"
# mode = "center"
# '';
in
{
options.xyno.desktop.wpaperd.enable = lib.mkEnableOption "enable wpaperd wallpaper daemon";
options.xyno.desktop.wpaperd.wantedBy = lib.mkOption {
type = lib.types.str;
default = "niri.service";
};
options.xyno.desktop.wpaperd.package = lib.mkOption {
type = lib.types.package;
default = pkgs.swww;
};
config = lib.mkIf cfg.enable {
environment.systemPackages = [ cfg.package ];
xyno.desktop.niri.extraConfig = ''
// Put swww inside the overview backdrop.
layer-rule {
match namespace="^swww.*$"
place-within-backdrop true
}
'';
systemd.user.services.swww-daemon = {
unitConfig.PartOf = "graphical-session.target";
unitConfig.After = "graphical-session.target";
unitConfig.Requisite = "graphical-session.target";
serviceConfig.Restart = "on-failure";
wantedBy = [ cfg.wantedBy ];
script = ''
exec ${cfg.package}/bin/swww-daemon'';
};
systemd.user.services.swww-randomize = {
unitConfig.PartOf = "graphical-session.target";
unitConfig.After = "graphical-session.target";
unitConfig.Requisite = "graphical-session.target";
serviceConfig.Restart = "on-failure";
wantedBy = [ "swww-daemon.service" ];
path = with pkgs;[ coreutils findutils cfg.package gnused];
script = ''
set -eox
export DEFAULT_INTERVAL=300 # In seconds
export DIR=''$HOME/Pictures/backgrounds
# See swww-img(1)
RESIZE_TYPE="crop"
export SWWW_TRANSITION_FPS="120"
export SWWW_TRANSITION="fade"
export SWWW_TRANSITION_DURATION="1"
# export SWWW_TRANSITION_STEP="90"
images=( ) # array of randomized images
while true; do
for d in ''$(swww query | sed -nE 's/^: ([^:]+).*/\1/p'); do # see swww-query(1)
if [[ ''${#images[@]} == 0 ]]; then
images=( $(find $DIR -regextype posix-extended -type f -regex '.*\.(jpg|jpeg|gif|png|bmp|dds|exr|ico|tga|tiff|webp)$' | shuf) ) # fill queue if arr empty (rust image crate supported formats)
fi
swww img --resize "''$RESIZE_TYPE" --outputs "''$d" "''${images[0]}" # show first image of arr
images=("''${images[@]:1}") # pop first image of arr
done
sleep "''${DEFAULT_INTERVAL}" || true # pkill sleep for next wallpaper xd
done
'';
# restartTriggers = [wpaperdConf];
};
};
}