From b22cabaa8d27199d88e74b92b5eac6c94c4ed4d2 Mon Sep 17 00:00:00 2001 From: Sean Kovacs Date: Sat, 13 Dec 2025 19:44:24 -0500 Subject: [PATCH] add bing wallpaper for niri --- home/tiling/niri/config/config.kdl | 6 +- home/tiling/niri/default.nix | 1 + home/tiling/wallpaper/bing-wallpaper.nix | 87 ++++++++++++++++++++++++ system/all.nix | 1 + 4 files changed, 93 insertions(+), 2 deletions(-) create mode 100644 home/tiling/wallpaper/bing-wallpaper.nix diff --git a/home/tiling/niri/config/config.kdl b/home/tiling/niri/config/config.kdl index 340ce5f..48391e6 100644 --- a/home/tiling/niri/config/config.kdl +++ b/home/tiling/niri/config/config.kdl @@ -257,6 +257,8 @@ layout { // This line starts waybar, a commonly used bar for Wayland compositors. // spawn-at-startup "waybar" +spawn-at-startup "swaybg" "-i" "/home/sckova/.local/share/dailywallpaper.jpg" + // run tailscale system tray spawn-at-startup "sudo tailscale set --operator=$USER" spawn-at-startup "tailscale systray" @@ -384,8 +386,8 @@ binds { // Example brightness key mappings for brightnessctl. // You can use regular spawn with multiple arguments too (to avoid going through "sh"), // but you need to manually put each argument in separate "" quotes. - XF86MonBrightnessUp allow-when-locked=true { spawn "/home/sckova/.config/niri/scripts/brightness.sh" "5"; } - XF86MonBrightnessDown allow-when-locked=true { spawn "/home/sckova/.config/niri/scripts/brightness.sh" "-5"; } + XF86MonBrightnessUp allow-when-locked=true { spawn "/home/sckova/.config/niri/scripts/brightness.sh" "1"; } + XF86MonBrightnessDown allow-when-locked=true { spawn "/home/sckova/.config/niri/scripts/brightness.sh" "-1"; } // Open/close the Overview: a zoomed-out view of workspaces and windows. // You can also move the mouse into the top-left hot corner, diff --git a/home/tiling/niri/default.nix b/home/tiling/niri/default.nix index e5396c5..4b28279 100644 --- a/home/tiling/niri/default.nix +++ b/home/tiling/niri/default.nix @@ -10,6 +10,7 @@ let in { home.packages = with pkgs; [ + swaybg swaylock fuzzel xdg-desktop-portal diff --git a/home/tiling/wallpaper/bing-wallpaper.nix b/home/tiling/wallpaper/bing-wallpaper.nix new file mode 100644 index 0000000..fcd67d8 --- /dev/null +++ b/home/tiling/wallpaper/bing-wallpaper.nix @@ -0,0 +1,87 @@ +{ pkgs, config, ... }: + +let + bingWallpaperScript = pkgs.writeShellScript "bing-wallpaper" '' + set -euo pipefail + + # Configuration + SIZE="1920x1080" + MARKET="en-US" + OUTPUT_PATH="''${XDG_DATA_HOME:-$HOME/.local/share}/dailywallpaper.jpg" + DAY="0" + + # API configuration + BING="https://www.bing.com" + API="/HPImageArchive.aspx" + REQ_IMG="$BING$API?format=js&idx=$DAY&mkt=$MARKET&n=1" + + echo "Pinging Bing API..." + + # Fetch API response + API_RESP=$(${pkgs.wget}/bin/wget --quiet --output-document=- "$REQ_IMG") + if (( $? > 0 )); then + echo "Ping failed!" + exit 1 + fi + + # Extract image URL base + URL_BASE=$(echo "$API_RESP" | ${pkgs.gnugrep}/bin/grep -oP 'urlbase":"[^"]*' | ${pkgs.coreutils}/bin/cut -d '"' -f 3) + REQ_IMG_URL="$BING$URL_BASE\_$SIZE.jpg" + + # Extract title + TITLE=$(echo "$API_RESP" | ${pkgs.gnugrep}/bin/grep -oP 'title":"[^"]*' | ${pkgs.coreutils}/bin/cut -d '"' -f 3) + + echo "Bing Image of the day: $TITLE" + + # Check if specific size exists, fallback to default + if ! ${pkgs.wget}/bin/wget --quiet --spider --max-redirect 0 "$REQ_IMG_URL"; then + REQ_IMG_URL="$BING$(echo "$API_RESP" | ${pkgs.gnugrep}/bin/grep -oP 'url":"[^"]*' | ${pkgs.coreutils}/bin/cut -d '"' -f 3)" + fi + + echo "$REQ_IMG_URL" + + # Extract filename + IMG_NAME="''${REQ_IMG_URL##*/}" + IMG_NAME="''${IMG_NAME#th?id=OHR.}" + IMG_NAME="''${IMG_NAME%&rf=*}" + + echo "$IMG_NAME" + + # Create parent directory + ${pkgs.coreutils}/bin/mkdir -p "$(${pkgs.coreutils}/bin/dirname "$OUTPUT_PATH")" + + # Download image, overwrite if exists + ${pkgs.wget}/bin/wget --quiet --output-document="$OUTPUT_PATH" "$REQ_IMG_URL" + + echo "Wallpaper saved to $OUTPUT_PATH" + + # Send notification + if command -v ${pkgs.libnotify}/bin/notify-send &> /dev/null; then + ${pkgs.libnotify}/bin/notify-send -u low -t 10 -i preferences-desktop-wallpaper \ + "Bing Wallpaper of the Day" "$TITLE" + fi + + echo "Wallpaper downloaded successfully." + ''; +in +{ + systemd.user.services.bing-wallpaper = { + Unit = { + Description = "Download and set Bing wallpaper of the day"; + After = [ + "network-online.target" + "niri.service" + ]; + Wants = [ "network-online.target" ]; + }; + + Service = { + Type = "oneshot"; + ExecStart = "${bingWallpaperScript}"; + }; + + Install = { + WantedBy = [ "niri.service" ]; + }; + }; +} diff --git a/system/all.nix b/system/all.nix index 3b1c6ee..9493c4c 100755 --- a/system/all.nix +++ b/system/all.nix @@ -29,6 +29,7 @@ ../home/browsers/firefox/default.nix ../home/tiling/niri/default.nix ../home/tiling/quickshell/default.nix + ../home/tiling/wallpaper/bing-wallpaper.nix ../home/tiling/waybar/default.nix ../home/tiling/noctalia/default.nix ../home/systemd/default.nix