From 7adeedbdd6287517fca8c0b8080221e77ad79b54 Mon Sep 17 00:00:00 2001 From: Ryan Schanzenbacher Date: Mon, 15 Jun 2026 00:54:41 -0400 Subject: Added wallpapers and logic to rotate them --- modules/darwin/random-wallpaper.nix | 40 +++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 modules/darwin/random-wallpaper.nix (limited to 'modules/darwin') diff --git a/modules/darwin/random-wallpaper.nix b/modules/darwin/random-wallpaper.nix new file mode 100644 index 0000000..6b17c0f --- /dev/null +++ b/modules/darwin/random-wallpaper.nix @@ -0,0 +1,40 @@ +{ config, lib, pkgs, ... }: +let + cfg = config.local.randomWallpaper; + script = pkgs.writeShellApplication { + name = "set-random-wallpaper"; + runtimeInputs = [ pkgs.coreutils pkgs.findutils ]; + text = '' + set -euo pipefail + img=$(find "${cfg.directory}" \ + -type f \( -iname '*.jpg' -o -iname '*.jpeg' -o -iname '*.png' \) \ + | shuf -n1) + [ -n "$img" ] || exit 0 + /usr/bin/osascript -e "tell application \"System Events\" to tell every desktop to set picture to \"$img\"" + ''; + }; +in +{ + options.local.randomWallpaper = { + enable = lib.mkEnableOption "Random Rotating Wallpaper"; + directory = lib.mkOption { + type = lib.types.str; + description = "Folder containing images"; + }; + interval = lib.mkOption { + type = lib.types.int; + default = 1800; + description = "Seconds between wallpaper changes"; + }; + }; + + config = lib.mkIf cfg.enable { + launchd.user.agents.random-wallpaper.serviceConfig = { + Label = "org.rschanz.wallpaperDaemon"; + ProgramArguments = [ "${script}/bin/set-random-wallpaper" ]; + StartInterval = cfg.interval; + RunAtLoad = true; + ProcessType = "Background"; + }; + }; +} -- cgit v1.3