nixos/system/home/swww.nix

61 lines
1.8 KiB
Nix

{ pkgs, ... }:
let
swwwMorning = "${pkgs.swww}/bin/swww img ${../wallpapers/tropic_island_morning.jpg}";
swwwDay = "${pkgs.swww}/bin/swww img ${../wallpapers/tropic_island_day.jpg}";
swwwEvening = "${pkgs.swww}/bin/swww img ${../wallpapers/tropic_island_evening.jpg}";
swwwNight = "${pkgs.swww}/bin/swww img ${../wallpapers/tropic_island_night.jpg}";
dynamicWallpaper = pkgs.writeShellScriptBin "dynamic-wallpaper" ''
swww query || exit 1 # Check SWWW daemon is actually running
case $(date +%H) in
06 | 07 | 08) # Morning
${swwwMorning}
;;
09 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17) # Day
${swwwDay}
;;
18 | 19 | 20) # Evening
${swwwEvening}
;;
21 | 22 | 23 | 00 | 01 | 02 | 03 | 04 | 05) # Night
${swwwNight}
;;
esac
'';
in
{
home.packages = with pkgs; [ swww ];
systemd.user = {
services = {
swww-daemon = {
Unit = {
Description = "SWWW Daemon";
Wants = [ "graphical-session.target" ];
After = [ "graphical-session.target" ];
};
Service.ExecStart = "${pkgs.swww}/bin/swww-daemon";
Install.WantedBy = [ "default.target" ];
};
dynamic-wallpaper = {
Unit = {
Description = "Change wallpaper based on time of day";
Wants = [ "swww-daemon.service" ];
After = [ "swww-daemon.service" ];
};
Service = {
Type = "oneshot";
ExecStart = "${dynamicWallpaper}/bin/dynamic-wallpaper";
};
Install.WantedBy = [ "default.target" ];
};
};
timers.dynamic-wallpaper = {
Install.WantedBy = [ "timers.target" ];
Timer = {
OnCalendar = "*:0";
Unit = "dynamic-wallpaper.service";
};
};
};
}