It is all a script now
This commit is contained in:
@@ -1,42 +1,114 @@
|
||||
{ config, pkgs, lib, flakeRoot, ... }:
|
||||
{ config, lib, pkgs, ... }:
|
||||
|
||||
let
|
||||
repoWallpaperDir = flakeRoot + "/assets/conf/desktop/wallpaper";
|
||||
repoWallpaperConf = flakeRoot + "/assets/conf/desktop/wallpaper/wallpaper.conf";
|
||||
userRelRoot = "nixos_conf/wallpaperstuff";
|
||||
userAbsRoot = "${config.home.homeDirectory}/${userRelRoot}";
|
||||
userConfPath = "${userAbsRoot}/wallpaper.conf";
|
||||
# Exclude wallpaper.conf so HM does NOT manage it (avoids backup collisions)
|
||||
repoWallpapersOnly = lib.cleanSourceWith {
|
||||
src = repoWallpaperDir;
|
||||
filter = path: type:
|
||||
(builtins.baseNameOf path) != "wallpaper.conf";
|
||||
};
|
||||
scriptPath = "hypr/scripts/wp-workspace-1to9.sh";
|
||||
|
||||
wpScript = ''
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
WALL_DIR="''${1:-$HOME/nixos_conf/wallpaperstuff/pictures}"
|
||||
|
||||
: "''${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" ]] || { echo "Hyprland socket not found: $SOCK" >&2; exit 1; }
|
||||
|
||||
need() { command -v "$1" >/dev/null 2>&1 || { echo "Missing dependency: $1" >&2; exit 1; }; }
|
||||
need hyprctl
|
||||
need wpaperctl
|
||||
need socat
|
||||
|
||||
get_active_ws_id() {
|
||||
if command -v jq >/dev/null 2>&1; then
|
||||
hyprctl activeworkspace -j | jq -r '.id'
|
||||
else
|
||||
hyprctl activeworkspace | awk '/workspace ID/ {print $3; exit}'
|
||||
fi
|
||||
}
|
||||
|
||||
get_active_monitor() {
|
||||
if command -v jq >/dev/null 2>&1; then
|
||||
hyprctl activeworkspace -j | jq -r '.monitor'
|
||||
else
|
||||
hyprctl activeworkspace | sed -n 's/.* on monitor \([^:]*\):.*/\1/p' | head -n1
|
||||
fi
|
||||
}
|
||||
|
||||
set_for_ws() {
|
||||
local ws_raw="$1"
|
||||
local ws="''${ws_raw%%:*}"
|
||||
[[ "$ws" =~ ^[1-9]$ ]] || return 0
|
||||
|
||||
local img="''${WALL_DIR}/wallpaper''${ws}.jpg"
|
||||
[[ -f "$img" ]] || return 0
|
||||
|
||||
local mon
|
||||
mon="$(get_active_monitor)"
|
||||
|
||||
if [[ -n "''${mon:-}" ]]; then
|
||||
wpaperctl set "$img" "$mon"
|
||||
else
|
||||
wpaperctl set "$img"
|
||||
fi
|
||||
}
|
||||
|
||||
preseed_1_to_9() {
|
||||
local orig
|
||||
orig="$(get_active_ws_id)"
|
||||
|
||||
for ws in {1..9}; do
|
||||
hyprctl dispatch workspace "$ws" >/dev/null
|
||||
sleep 0.05
|
||||
set_for_ws "$ws"
|
||||
done
|
||||
|
||||
hyprctl dispatch workspace "$orig" >/dev/null
|
||||
}
|
||||
|
||||
# Start daemon if not already running
|
||||
if ! pgrep -x wpaperd >/dev/null; then
|
||||
wpaperd -d &
|
||||
sleep 0.5
|
||||
fi
|
||||
|
||||
preseed_1_to_9
|
||||
set_for_ws "$(get_active_ws_id)"
|
||||
|
||||
while IFS= read -r line; do
|
||||
case "$line" in
|
||||
workspace\>\>*)
|
||||
set_for_ws "''${line#workspace>>}"
|
||||
;;
|
||||
workspacev2\>\>*)
|
||||
payload="''${line#workspacev2>>}"
|
||||
ws_id="''${payload%%,*}"
|
||||
set_for_ws "$ws_id"
|
||||
;;
|
||||
esac
|
||||
done < <(socat -U - "UNIX-CONNECT:''${SOCK}")
|
||||
'';
|
||||
in
|
||||
{
|
||||
home.packages = [ pkgs.wpaperd ];
|
||||
# Sync everything *except* wallpaper.conf into ~/nixos_conf/wallpaperstuff
|
||||
home.file."${userRelRoot}" = {
|
||||
source = repoWallpapersOnly;
|
||||
recursive = true;
|
||||
home.packages = with pkgs; [
|
||||
wpaperd
|
||||
socat
|
||||
jq
|
||||
];
|
||||
|
||||
# Write script
|
||||
xdg.configFile."${scriptPath}" = {
|
||||
text = wpScript;
|
||||
executable = true;
|
||||
};
|
||||
# Now safely overwrite the config every activation (no HM collision)
|
||||
home.activation.wallpaperConfForce =
|
||||
lib.hm.dag.entryAfter [ "writeBoundary" ] ''
|
||||
set -euo pipefail
|
||||
mkdir -p "${userAbsRoot}"
|
||||
install -m 0644 "${repoWallpaperConf}" "${userConfPath}"
|
||||
|
||||
# Ensure Hyprland starts it
|
||||
wayland.windowManager.hyprland = {
|
||||
enable = true;
|
||||
|
||||
extraConfig = ''
|
||||
exec-once = ${config.xdg.configHome}/${scriptPath}
|
||||
'';
|
||||
systemd.user.services.wpaperd = {
|
||||
Unit = {
|
||||
Description = "wpaperd wallpaper daemon";
|
||||
After = [ "default.target" ];
|
||||
};
|
||||
Service = {
|
||||
Type = "simple";
|
||||
ExecStart = "${pkgs.wpaperd}/bin/wpaperd --config ${userConfPath}";
|
||||
Restart = "on-failure";
|
||||
RestartSec = 1;
|
||||
};
|
||||
Install.WantedBy = [ "default.target" ];
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user