nix-dotfiles/modules/update_background.nix

40 lines
1.2 KiB
Nix

{ pkgs, config, ... }:
let
fehCmd = "${pkgs.feh}/bin/feh";
backgrounds_directory = ~/Immagini/Sfondi;
update_time = "10m";
in
{
home.file.".local/bin/update_background.sh" = {
text = ''
#!${pkgs.bash}/bin/bash
image=`find ${backgrounds_directory} -type f | grep -v "/\." | shuf -n 1`
${fehCmd} --bg-fill --no-fehbg "$image"
'';
target = ".local/bin/update_background.sh";
executable = true;
};
systemd.user.services."update-background" = {
Unit = {
Description = "Set random desktop background using feh";
After = [ "graphical-session.pre.target" ];
PartOf = [ "graphical-session.target" ];
RequiresMountsFor = [ "/home/bertof/Immagini" ];
};
Install = {
WantedBy = [ "graphical-session.target" ];
};
Service = {
Type = "oneshot";
IOSchedulingClass = "idle";
ExecStart = "${config.home.homeDirectory}/${config.home.file.".local/bin/update_background.sh".target}";
};
};
systemd.user.timers."update-background" = {
Unit = { Description = "Set random desktop background using feh"; };
Timer = { OnUnitActiveSec = update_time; };
Install = { WantedBy = [ "timers.target" ]; };
};
}