modules/darwin/random-wallpaper.nix
1d64a259eb2f377b7b7dc36263eaf33d4a7cf28c
· 1.2 KB · 41 lines
raw
| 1 | { config, lib, pkgs, ... }: |
| 2 | let |
| 3 | cfg = config.local.randomWallpaper; |
| 4 | script = pkgs.writeShellApplication { |
| 5 | name = "set-random-wallpaper"; |
| 6 | runtimeInputs = [ pkgs.coreutils pkgs.findutils pkgs.desktoppr]; |
| 7 | text = '' |
| 8 | set -euo pipefail |
| 9 | img=$(find "${cfg.directory}" \ |
| 10 | -type f \( -iname '*.jpg' -o -iname '*.jpeg' -o -iname '*.png' \) \ |
| 11 | | shuf -n1) |
| 12 | [ -n "$img" ] || exit 0 |
| 13 | #/usr/bin/osascript -e "tell application \"System Events\" to tell every desktop to set picture to \"$img\"" |
| 14 | desktoppr "$img" |
| 15 | ''; |
| 16 | }; |
| 17 | in |
| 18 | { |
| 19 | options.local.randomWallpaper = { |
| 20 | enable = lib.mkEnableOption "Random Rotating Wallpaper"; |
| 21 | directory = lib.mkOption { |
| 22 | type = lib.types.str; |
| 23 | description = "Folder containing images"; |
| 24 | }; |
| 25 | interval = lib.mkOption { |
| 26 | type = lib.types.int; |
| 27 | default = 1800; |
| 28 | description = "Seconds between wallpaper changes"; |
| 29 | }; |
| 30 | }; |
| 31 | |
| 32 | config = lib.mkIf cfg.enable { |
| 33 | launchd.user.agents.random-wallpaper.serviceConfig = { |
| 34 | Label = "org.rschanz.wallpaperDaemon"; |
| 35 | ProgramArguments = [ "${script}/bin/set-random-wallpaper" ]; |
| 36 | StartInterval = cfg.interval; |
| 37 | RunAtLoad = true; |
| 38 | ProcessType = "Background"; |
| 39 | }; |
| 40 | }; |
| 41 | } |