New script with writable toml

This commit is contained in:
2026-02-26 21:04:59 +01:00
parent 6ac406218f
commit 9445a13169
5 changed files with 726 additions and 862 deletions
+36 -107
View File
@@ -1,114 +1,43 @@
{ config, lib, pkgs, ... }:
#+begin_src nix :tangle home/desktop/wallpaper.nix :noweb tangle :mkdirp yes
{ config, pkgs, lib, flakeRoot, ... }:
let
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}")
'';
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";
};
in
{
home.packages = with pkgs; [
wpaperd
socat
jq
];
# Write script
xdg.configFile."${scriptPath}" = {
text = wpScript;
executable = true;
home.packages = [ pkgs.wpaperd ];
# Sync everything *except* wallpaper.conf into ~/nixos_conf/wallpaperstuff
home.file."${userRelRoot}" = {
source = repoWallpapersOnly;
recursive = true;
};
# Ensure Hyprland starts it
wayland.windowManager.hyprland = {
enable = true;
extraConfig = ''
exec-once = ${config.xdg.configHome}/${scriptPath}
# 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}"
'';
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" ];
};
}