It is all a script now

This commit is contained in:
2026-02-26 19:45:26 +01:00
parent 7bde9df064
commit 6ac406218f
3 changed files with 633 additions and 812 deletions
+423 -552
View File
File diff suppressed because it is too large Load Diff
+103 -225
View File
@@ -1662,241 +1662,119 @@ This module will import all necessities.
rotating_wallpaper.nix installs wpaperd and deploys your wallpaper files from the repo (./assets/conf/desktop/wallpaper/pictures/) into ~/conf/desktop/wallpaper/pictures. It also deploys the default wallpaper configuration from assets/conf/desktop/wallpaper/wallpaper.conf into ~/conf/desktop/wallpaper/wallpaper.conf, which is the file you can edit as a user override.
Finally, it creates a systemd user service (wpaperd.service) that automatically starts wpaperd at login and keeps it running, using your override config so wallpapers rotate according to your settings.
#+begin_src nix :tangle home/desktop/rotating_wallpaper.nix :noweb tangle :mkdirp yes
{ 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;
};
# 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" ];
};
}
#+end_src
** Workspace_Wallpaper
workspace_wallpaper installs wpaperd and deploys your wallpaper files from the repo (./assets/conf/desktop/wallpaper/pictures/) into ~/conf/desktop/wallpaper/pictures. It also deploys the default wallpaper configuration from assets/conf/desktop/wallpaper/wallpaper.conf into ~/conf/desktop/wallpaper/wallpaper.conf, which is the file you can edit as a user override.
#+begin_src nix :tangle home/desktop/workspace_wallpaper.nix :noweb tangle :mkdirp yes
{ config, pkgs, lib, flakeRoot, ... }:
let
# Repo folder that gets copied to ~/nixos_conf/wallpaperstuff
repoWallpaperDir = flakeRoot + "/assets/conf/desktop/wallpaper";
userRelRoot = "nixos_conf/wallpaperstuff";
userAbsRoot = "${config.home.homeDirectory}/${userRelRoot}";
# Your actual layout:
# ~/nixos_conf/wallpaperstuff/pictures/wallpaper{1..9}.jpg
picturesDir = "${userAbsRoot}/pictures";
stateDir = "${userAbsRoot}/current";
symlinkPath = "${stateDir}/workspace.jpg";
scriptRel = "hypr/scripts/wpaperd-workspace-1to9.sh";
wpaperdConfRel = "wpaperd/config.toml";
in
{
home.packages = [
pkgs.wpaperd
pkgs.socat
pkgs.jq
home.packages = with pkgs; [
wpaperd
socat
jq
];
# Copy wallpapers from repo → ~/nixos_conf/wallpaperstuff (includes pictures/)
home.file."${userRelRoot}" = {
source = repoWallpaperDir;
recursive = true;
};
# Ensure wpaperd config points to the global symlink (not per-monitor, not rotating)
xdg.configFile."${wpaperdConfRel}".text = ''
[default]
mode = "stretch"
[any]
path = "${symlinkPath}"
'';
# Script: global wallpaper per workspace (focused workspace), via symlink + reload-wallpaper
xdg.configFile."${scriptRel}" = {
# Write script
xdg.configFile."${scriptPath}" = {
text = wpScript;
executable = true;
text = ''
#!/usr/bin/env bash
set -euo pipefail
};
log() { echo "[wpaperd-ws] $*" >&2; }
# Ensure Hyprland starts it
wayland.windowManager.hyprland = {
enable = true;
PICTURES_DIR="${picturesDir}"
STATE_DIR="${stateDir}"
SYMLINK="${symlinkPath}"
XDG_CONFIG_HOME="''${XDG_CONFIG_HOME:-$HOME/.config}"
WPAPERD_DIR="$XDG_CONFIG_HOME/wpaperd"
CONF="$WPAPERD_DIR/config.toml"
: "''${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"
mkdir -p "$STATE_DIR" "$WPAPERD_DIR"
# Wait for Hyprland socket so we don't exit too early
for i in $(seq 1 120); do
[[ -S "$SOCK" ]] && break
sleep 0.1
done
[[ -S "$SOCK" ]] || { log "Hyprland socket not found: $SOCK"; exit 1; }
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' "$PICTURES_DIR" "$n" ;;
*) return 1 ;;
esac
}
ensure_config() {
# keep config stable and always pointing to the symlink
cat >"$CONF" <<EOF
[default]
mode = "stretch"
[any]
path = "$SYMLINK"
EOF
}
reload_wallpaper() {
${pkgs.wpaperd}/bin/wpaperctl reload-wallpaper >/dev/null 2>&1 || true
}
apply_workspace() {
local ws_raw="$1"
local n img
n="$(ws_num "$ws_raw")" || { log "Ignoring non-numeric workspace: $ws_raw"; return 0; }
img="$(img_for_ws "$n")" || return 0
if [[ ! -f "$img" ]]; then
log "Missing image for ws=$n: $img"
return 0
fi
# If already set, skip
if [[ -L "$SYMLINK" ]] && [[ "$(readlink -f "$SYMLINK")" == "$(readlink -f "$img")" ]]; then
return 0
fi
ln -sf "$img" "$SYMLINK"
log "Workspace $n -> $img"
ensure_config
reload_wallpaper
}
apply_initial() {
local ws
ws="$(${pkgs.hyprland}/bin/hyprctl -j monitors | ${pkgs.jq}/bin/jq -r '.[] | select(.focused==true) | .activeWorkspace.name' | head -n1)"
if [[ -n "$ws" && "$ws" != "null" ]]; then
apply_workspace "$ws"
else
log "Could not determine initial focused workspace"
fi
}
handle_line() {
case "$1" in
workspace\>\>*)
apply_workspace "''${1#workspace>>}"
;;
workspacev2\>\>*)
local payload="''${1#workspacev2>>}"
apply_workspace "''${payload#*,}"
;;
focusedmon\>\>*)
local payload="''${1#focusedmon>>}"
local ws="''${payload#*,}"
apply_workspace "$ws"
;;
esac
}
ensure_config
apply_initial
log "Listening on $SOCK"
exec ${pkgs.socat}/bin/socat -U - "UNIX-CONNECT:$SOCK" \
| while IFS= read -r line; do
handle_line "$line" || true
done
extraConfig = ''
exec-once = ${config.xdg.configHome}/${scriptPath}
'';
};
# wpaperd daemon
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";
RestartSec = 1;
};
Install.WantedBy = [ "graphical-session.target" ];
};
# listener
systemd.user.services.wpaperd-workspace-wallpaper = {
Unit = {
Description = "Global wallpaper per workspace (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";
RestartSec = 1;
};
Install.WantedBy = [ "graphical-session.target" ];
};
}
#+end_src
+107 -35
View File
@@ -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" ];
};
}