{ config, pkgs, lib, flakeRoot, ... }: let repoWallpaperDir = flakeRoot + "/assets/conf/desktop/wallpaper"; userRelRoot = "nixos_conf/wallpaperstuff"; userAbsRoot = "${config.home.homeDirectory}/${userRelRoot}"; scriptRel = "hypr/scripts/wpaperd-workspace-1to9.sh"; in { home.packages = [ pkgs.wpaperd pkgs.socat pkgs.jq ]; # Copy wallpapers from repo → ~/nixos_conf/wallpaperstuff home.file."${userRelRoot}" = { source = repoWallpaperDir; recursive = true; }; # Workspace listener script (no wpaperd config needed) xdg.configFile."${scriptRel}".text = '' #!/usr/bin/env bash set -euo pipefail ROOT="${userAbsRoot}" : "''${XDG_RUNTIME_DIR:?XDG_RUNTIME_DIR not set}" : "''${HYPRLAND_INSTANCE_SIGNATURE:?HYPRLAND_INSTANCE_SIGNATURE not set}" SOCK="''${XDG_RUNTIME_DIR}/hypr/''${HYPRLAND_INSTANCE_SIGNATURE}/.socket2.sock" [[ -S "$SOCK" ]] || exit 0 # Extract numeric workspace prefix from "1" or "1:foo" ws_num() { local w="''${1%%:*}" [[ "$w" =~ ^[0-9]+$ ]] || return 1 printf '%s\n' "$w" } img_for_ws() { local n="$1" case "$n" in 1|2|3|4|5|6|7|8|9) printf '%s/wallpaper%s.jpg\n' "$ROOT" "$n" ;; *) return 1 ;; esac } apply_for() { local mon="$1" local ws="$2" local n n="$(ws_num "$ws")" || return 0 local img img="$(img_for_ws "$n")" || return 0 [[ -f "$img" ]] || return 0 # Set wallpaper for specific monitor (supported by wpaperctl) ${pkgs.wpaperd}/bin/wpaperctl set "$img" "$mon" >/dev/null 2>&1 || true } apply_initial() { # For each monitor, read its activeWorkspace.name and apply once at startup ${pkgs.hyprland}/bin/hyprctl -j monitors \ | ${pkgs.jq}/bin/jq -r '.[] | "\(.name)\t\(.activeWorkspace.name)"' \ | while IFS=$'\t' read -r mon ws; do [[ -n "$mon" && -n "$ws" ]] || continue apply_for "$mon" "$ws" done } handle_line() { case "$1" in focusedmon\>\>*) # focusedmon>>MONNAME,WORKSPACENAME local payload="''${1#focusedmon>>}" local mon="''${payload%%,*}" local ws="''${payload#*,}" apply_for "$mon" "$ws" ;; workspace\>\>*) # workspace>>WORKSPACENAME (no monitor info) — ignore ;; workspacev2\>\>*) # workspacev2>>ID,NAME (no monitor info) — ignore ;; esac } apply_initial exec ${pkgs.socat}/bin/socat -U - "UNIX-CONNECT:$SOCK" \ | while IFS= read -r line; do handle_line "$line" || true done ''; xdg.configFile."${scriptRel}".executable = true; # Start wpaperd systemd.user.services.wpaperd = { Unit = { Description = "wpaperd wallpaper daemon"; After = [ "graphical-session.target" ]; PartOf = [ "graphical-session.target" ]; }; Service = { ExecStart = "${pkgs.wpaperd}/bin/wpaperd"; Restart = "on-failure"; }; Install.WantedBy = [ "graphical-session.target" ]; }; # Listen to Hyprland workspace/monitor focus and set wallpapers accordingly systemd.user.services.wpaperd-workspace-wallpapers = { Unit = { Description = "Set wallpaper based on workspace number (1..9)"; After = [ "graphical-session.target" "wpaperd.service" ]; PartOf = [ "graphical-session.target" ]; }; Service = { ExecStart = "${pkgs.bash}/bin/bash ${config.xdg.configHome}/${scriptRel}"; Restart = "on-failure"; }; Install.WantedBy = [ "graphical-session.target" ]; }; }