Let's try using hyprpaper

This commit is contained in:
2026-02-26 21:12:11 +01:00
parent 9445a13169
commit 874cdd1c7a
5 changed files with 632 additions and 477 deletions
+413 -361
View File
File diff suppressed because it is too large Load Diff
+110 -58
View File
@@ -1758,8 +1758,8 @@ in
RestartSec = 1; RestartSec = 1;
}; };
Install.WantedBy = [ "default.target" ]; Install.WantedBy = [ "default.target" ];
}; ;
}
#+end_src #+end_src
** Workspace Wallpaper ** Workspace Wallpaper
@@ -1767,31 +1767,28 @@ in
{ config, lib, pkgs, flakeRoot, ... }: { config, lib, pkgs, flakeRoot, ... }:
let let
# Repo inputs # Repo inputs (same as you had)
repoWallpaperDir = flakeRoot + "/assets/conf/desktop/wallpaper"; repoWallpaperDir = flakeRoot + "/assets/conf/desktop/wallpaper";
# Where we sync assets to (writable) # Where we sync assets to (writable)
userRelRoot = "nixos_conf/wallpaperstuff"; userRelRoot = "nixos_conf/wallpaperstuff";
userAbsRoot = "${config.home.homeDirectory}/${userRelRoot}"; userAbsRoot = "${config.home.homeDirectory}/${userRelRoot}";
picturesDir = "${userAbsRoot}/pictures"; picturesDir = "${userAbsRoot}/pictures";
# Writable runtime TOML (NOT under ~/.config) # Sync everything in repoWallpaperDir to ~/nixos_conf/wallpaperstuff
runtimeConf = "${userAbsRoot}/wpaperd-runtime.toml";
# Your generator script (synced from repo into userAbsRoot)
wsScript = "${userAbsRoot}/wpaperd-workspace-1to9.sh";
# Sync everything in repoWallpaperDir to ~/nixos_conf/wallpaperstuff,
# but keep it simple: we exclude no files here unless you want to.
repoWallpapersOnly = lib.cleanSourceWith { repoWallpapersOnly = lib.cleanSourceWith {
src = repoWallpaperDir; src = repoWallpaperDir;
filter = path: type: true; filter = path: type: true;
}; };
# Workspace→wallpaper listener script
wsScriptRel = "hypr/scripts/hyprpaper-workspace-1to9.sh";
in in
{ {
home.packages = [ home.packages = [
pkgs.wpaperd pkgs.hyprpaper
pkgs.socat
pkgs.jq
]; ];
# 1) Sync your wallpaper assets + scripts into a writable location # 1) Sync your wallpaper assets + scripts into a writable location
@@ -1800,66 +1797,121 @@ in
recursive = true; recursive = true;
}; };
# 2) Ensure we have a writable runtime config (created if missing) # 2) hyprpaper config (read-only is fine; hyprpaper doesn't need to write it)
# # Location per wiki: ~/.config/hypr/hyprpaper.conf :contentReference[oaicite:1]{index=1}
# NOTE: We intentionally do NOT create ~/.config/wpaperd/config.toml via HM, xdg.configFile."hypr/hyprpaper.conf".text = ''
# because HM places managed files in /nix/store and symlinks them (read-only), # Managed by Home Manager
# which breaks apps/scripts that want to write there. ipc = true
home.activation.ensureWpaperdRuntimeConf = splash = false
lib.hm.dag.entryAfter [ "writeBoundary" ] ''
mkdir -p "${userAbsRoot}"
mkdir -p "${picturesDir}"
if [ ! -f "${runtimeConf}" ]; then # Fallback wallpaper (only used for monitors that never got a specific one yet)
cat > "${runtimeConf}" <<'EOF' wallpaper {
[default] monitor =
mode = "stretch" path = ${picturesDir}
fit_mode = fill
timeout = 3600
}
'';
# Fallback for outputs not explicitly listed: # 3) Install the listener script at ~/.config/hypr/scripts/...
[any] xdg.configFile."${wsScriptRel}".executable = true;
path = "__WALLPAPER_DIR__" xdg.configFile."${wsScriptRel}".text = ''
EOF #!/usr/bin/env bash
# default: point [any].path at your pictures dir set -euo pipefail
${pkgs.gnused}/bin/sed -i "s|__WALLPAPER_DIR__|${picturesDir}|g" "${runtimeConf}"
fi
'';
# 3) wpaperd user service: always use the writable runtime config : "''${XDG_RUNTIME_DIR:?XDG_RUNTIME_DIR not set}"
systemd.user.services.wpaperd = { : "''${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; }
PICTURES_DIR="''${1:-${picturesDir}}"
FIT_MODE="fill" # hyprpaper fit_mode: contain|cover|tile|fill (fill stretch) :contentReference[oaicite:2]{index=2}
# Track focused monitor (workspace events do not include monitor name) :contentReference[oaicite:3]{index=3}
FOCUSED_MON=""
pick_wall_for_ws() {
local ws="$1"
# Prefer exact matches like 1.png / 1.jpg / 1.webp / 1.jxl etc.
# Pick first match; if none, return empty.
local f
f="$(ls -1 "${PICTURES_DIR}/${ws}."* 2>/dev/null | head -n 1 || true)"
echo "$f"
}
apply_wallpaper() {
local mon="$1"
local ws="$2"
local file
file="$(pick_wall_for_ws "$ws")"
[[ -n "$file" ]] || return 0
# hyprpaper IPC via hyprctl: hyprctl hyprpaper wallpaper '[mon], [path], [fit_mode]' :contentReference[oaicite:4]{index=4}
# Note: wiki shows commas + optional fit_mode; keep it explicit.
hyprctl hyprpaper wallpaper "${mon}, ${file}, ${FIT_MODE}" >/dev/null
}
# Initial state
# focused monitor from hyprctl monitors
FOCUSED_MON="$(hyprctl -j monitors | jq -r '.[] | select(.focused==true) | .name' | head -n 1)"
# workspace name (may be "1" or "1:something")
CUR_WS="$(hyprctl -j activeworkspace | jq -r '.name' | head -n 1)"
CUR_WS="''${CUR_WS%%:*}"
[[ -n "$FOCUSED_MON" && -n "$CUR_WS" ]] && apply_wallpaper "$FOCUSED_MON" "$CUR_WS"
handle() {
case "$1" in
focusedmon* )
# format: focusedmon>>MONNAME,WORKSPACENAME :contentReference[oaicite:5]{index=5}
local payload="''${1#*>>}"
FOCUSED_MON="''${payload%%,*}"
;;
workspace* )
# format: workspace>>WORKSPACENAME :contentReference[oaicite:6]{index=6}
local ws="''${1#*>>}"
ws="''${ws%%:*}"
ws="''${ws%% *}" # trim trailing space if present
[[ -n "$FOCUSED_MON" && -n "$ws" ]] && apply_wallpaper "$FOCUSED_MON" "$ws"
;;
esac
}
# Listen to socket2 events via socat (wiki example) :contentReference[oaicite:7]{index=7}
socat -U - UNIX-CONNECT:"$SOCK" | while read -r line; do
handle "$line" || true
done
'';
# 4) Start hyprpaper + the workspace listener as user services
systemd.user.services.hyprpaper = {
Unit = { Unit = {
Description = "wpaperd wallpaper daemon (runtime config)"; Description = "hyprpaper wallpaper daemon";
PartOf = [ "graphical-session.target" ]; PartOf = [ "graphical-session.target" ];
After = [ "graphical-session.target" ]; After = [ "graphical-session.target" ];
}; };
Service = { Service = {
ExecStart = "${pkgs.wpaperd}/bin/wpaperd --config ${runtimeConf}"; ExecStart = "${pkgs.hyprpaper}/bin/hyprpaper";
Restart = "on-failure"; Restart = "on-failure";
RestartSec = 1; RestartSec = 1;
}; };
Install = { WantedBy = [ "graphical-session.target" ]; };
Install = {
WantedBy = [ "graphical-session.target" ];
};
}; };
# 4) Optional: run your workspace generator once per login, then restart wpaperd systemd.user.services.hyprpaper-workspace-wallpapers = {
systemd.user.services.wpaperd-workspaces-init = {
Unit = { Unit = {
Description = "Generate workspace wallpapers (wpaperd runtime config)"; Description = "Hyprpaper workspace wallpapers (socket2 listener)";
PartOf = [ "graphical-session.target" ]; PartOf = [ "graphical-session.target" ];
After = [ "graphical-session.target" ]; After = [ "graphical-session.target" "hyprpaper.service" ];
}; };
Service = { Service = {
Type = "oneshot"; ExecStart = "${pkgs.bash}/bin/bash ${config.xdg.configHome}/${wsScriptRel} ${picturesDir}";
ExecStart = "${pkgs.bash}/bin/bash ${wsScript} ${picturesDir}"; Restart = "on-failure";
ExecStartPost = "${pkgs.systemd}/bin/systemctl --user restart wpaperd"; RestartSec = 1;
};
Install = {
WantedBy = [ "graphical-session.target" ];
}; };
Install = { WantedBy = [ "graphical-session.target" ]; };
}; };
} }
#+end_src #+end_src
@@ -1871,7 +1923,7 @@ EOF
Mostly styling and enabling modules in the [[https://github.com/Alexays/Waybar][top bar]]. Mostly styling and enabling modules in the [[https://github.com/Alexays/Waybar][top bar]].
#+begin_src nix :tangle home/desktop/waybar.nix :noweb tangle :mkdirp yes #+begin_src nix :tangle home/desktop/waybar.nix :noweb tangle :mkdirp yes
{ config, lib, pkgs, flakeRoot, ... }: { config, lib, pkgs, flakeRoot, ... :
let let
repoWaybarDir = flakeRoot + "/assets/conf/desktop/waybar"; repoWaybarDir = flakeRoot + "/assets/conf/desktop/waybar";
in in
@@ -1882,7 +1934,7 @@ in
xdg.configFile."waybar/config" = { xdg.configFile."waybar/config" = {
source = repoWaybarDir + "/config.jsonc"; source = repoWaybarDir + "/config.jsonc";
force = true; force = true;
}; ;
# Override HM's internally-generated waybar-style.css derivation # Override HM's internally-generated waybar-style.css derivation
# and use your repo file instead. # and use your repo file instead.
@@ -39,5 +39,4 @@ in
RestartSec = 1; RestartSec = 1;
}; };
Install.WantedBy = [ "default.target" ]; Install.WantedBy = [ "default.target" ];
}; ;
}
+2 -2
View File
@@ -1,4 +1,4 @@
{ config, lib, pkgs, flakeRoot, ... }: { config, lib, pkgs, flakeRoot, ... :
let let
repoWaybarDir = flakeRoot + "/assets/conf/desktop/waybar"; repoWaybarDir = flakeRoot + "/assets/conf/desktop/waybar";
in in
@@ -9,7 +9,7 @@ in
xdg.configFile."waybar/config" = { xdg.configFile."waybar/config" = {
source = repoWaybarDir + "/config.jsonc"; source = repoWaybarDir + "/config.jsonc";
force = true; force = true;
}; ;
# Override HM's internally-generated waybar-style.css derivation # Override HM's internally-generated waybar-style.css derivation
# and use your repo file instead. # and use your repo file instead.
+106 -54
View File
@@ -1,31 +1,28 @@
{ config, lib, pkgs, flakeRoot, ... }: { config, lib, pkgs, flakeRoot, ... }:
let let
# Repo inputs # Repo inputs (same as you had)
repoWallpaperDir = flakeRoot + "/assets/conf/desktop/wallpaper"; repoWallpaperDir = flakeRoot + "/assets/conf/desktop/wallpaper";
# Where we sync assets to (writable) # Where we sync assets to (writable)
userRelRoot = "nixos_conf/wallpaperstuff"; userRelRoot = "nixos_conf/wallpaperstuff";
userAbsRoot = "${config.home.homeDirectory}/${userRelRoot}"; userAbsRoot = "${config.home.homeDirectory}/${userRelRoot}";
picturesDir = "${userAbsRoot}/pictures"; picturesDir = "${userAbsRoot}/pictures";
# Writable runtime TOML (NOT under ~/.config) # Sync everything in repoWallpaperDir to ~/nixos_conf/wallpaperstuff
runtimeConf = "${userAbsRoot}/wpaperd-runtime.toml";
# Your generator script (synced from repo into userAbsRoot)
wsScript = "${userAbsRoot}/wpaperd-workspace-1to9.sh";
# Sync everything in repoWallpaperDir to ~/nixos_conf/wallpaperstuff,
# but keep it simple: we exclude no files here unless you want to.
repoWallpapersOnly = lib.cleanSourceWith { repoWallpapersOnly = lib.cleanSourceWith {
src = repoWallpaperDir; src = repoWallpaperDir;
filter = path: type: true; filter = path: type: true;
}; };
# Workspace→wallpaper listener script
wsScriptRel = "hypr/scripts/hyprpaper-workspace-1to9.sh";
in in
{ {
home.packages = [ home.packages = [
pkgs.wpaperd pkgs.hyprpaper
pkgs.socat
pkgs.jq
]; ];
# 1) Sync your wallpaper assets + scripts into a writable location # 1) Sync your wallpaper assets + scripts into a writable location
@@ -34,65 +31,120 @@ in
recursive = true; recursive = true;
}; };
# 2) Ensure we have a writable runtime config (created if missing) # 2) hyprpaper config (read-only is fine; hyprpaper doesn't need to write it)
# # Location per wiki: ~/.config/hypr/hyprpaper.conf :contentReference[oaicite:1]{index=1}
# NOTE: We intentionally do NOT create ~/.config/wpaperd/config.toml via HM, xdg.configFile."hypr/hyprpaper.conf".text = ''
# because HM places managed files in /nix/store and symlinks them (read-only), # Managed by Home Manager
# which breaks apps/scripts that want to write there. ipc = true
home.activation.ensureWpaperdRuntimeConf = splash = false
lib.hm.dag.entryAfter [ "writeBoundary" ] ''
mkdir -p "${userAbsRoot}"
mkdir -p "${picturesDir}"
if [ ! -f "${runtimeConf}" ]; then # Fallback wallpaper (only used for monitors that never got a specific one yet)
cat > "${runtimeConf}" <<'EOF' wallpaper {
[default] monitor =
mode = "stretch" path = ${picturesDir}
fit_mode = fill
timeout = 3600
}
'';
# Fallback for outputs not explicitly listed: # 3) Install the listener script at ~/.config/hypr/scripts/...
[any] xdg.configFile."${wsScriptRel}".executable = true;
path = "__WALLPAPER_DIR__" xdg.configFile."${wsScriptRel}".text = ''
EOF #!/usr/bin/env bash
# default: point [any].path at your pictures dir set -euo pipefail
${pkgs.gnused}/bin/sed -i "s|__WALLPAPER_DIR__|${picturesDir}|g" "${runtimeConf}"
fi
'';
# 3) wpaperd user service: always use the writable runtime config : "''${XDG_RUNTIME_DIR:?XDG_RUNTIME_DIR not set}"
systemd.user.services.wpaperd = { : "''${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; }
PICTURES_DIR="''${1:-${picturesDir}}"
FIT_MODE="fill" # hyprpaper fit_mode: contain|cover|tile|fill (fill stretch) :contentReference[oaicite:2]{index=2}
# Track focused monitor (workspace events do not include monitor name) :contentReference[oaicite:3]{index=3}
FOCUSED_MON=""
pick_wall_for_ws() {
local ws="$1"
# Prefer exact matches like 1.png / 1.jpg / 1.webp / 1.jxl etc.
# Pick first match; if none, return empty.
local f
f="$(ls -1 "${PICTURES_DIR}/${ws}."* 2>/dev/null | head -n 1 || true)"
echo "$f"
}
apply_wallpaper() {
local mon="$1"
local ws="$2"
local file
file="$(pick_wall_for_ws "$ws")"
[[ -n "$file" ]] || return 0
# hyprpaper IPC via hyprctl: hyprctl hyprpaper wallpaper '[mon], [path], [fit_mode]' :contentReference[oaicite:4]{index=4}
# Note: wiki shows commas + optional fit_mode; keep it explicit.
hyprctl hyprpaper wallpaper "${mon}, ${file}, ${FIT_MODE}" >/dev/null
}
# Initial state
# focused monitor from hyprctl monitors
FOCUSED_MON="$(hyprctl -j monitors | jq -r '.[] | select(.focused==true) | .name' | head -n 1)"
# workspace name (may be "1" or "1:something")
CUR_WS="$(hyprctl -j activeworkspace | jq -r '.name' | head -n 1)"
CUR_WS="''${CUR_WS%%:*}"
[[ -n "$FOCUSED_MON" && -n "$CUR_WS" ]] && apply_wallpaper "$FOCUSED_MON" "$CUR_WS"
handle() {
case "$1" in
focusedmon* )
# format: focusedmon>>MONNAME,WORKSPACENAME :contentReference[oaicite:5]{index=5}
local payload="''${1#*>>}"
FOCUSED_MON="''${payload%%,*}"
;;
workspace* )
# format: workspace>>WORKSPACENAME :contentReference[oaicite:6]{index=6}
local ws="''${1#*>>}"
ws="''${ws%%:*}"
ws="''${ws%% *}" # trim trailing space if present
[[ -n "$FOCUSED_MON" && -n "$ws" ]] && apply_wallpaper "$FOCUSED_MON" "$ws"
;;
esac
}
# Listen to socket2 events via socat (wiki example) :contentReference[oaicite:7]{index=7}
socat -U - UNIX-CONNECT:"$SOCK" | while read -r line; do
handle "$line" || true
done
'';
# 4) Start hyprpaper + the workspace listener as user services
systemd.user.services.hyprpaper = {
Unit = { Unit = {
Description = "wpaperd wallpaper daemon (runtime config)"; Description = "hyprpaper wallpaper daemon";
PartOf = [ "graphical-session.target" ]; PartOf = [ "graphical-session.target" ];
After = [ "graphical-session.target" ]; After = [ "graphical-session.target" ];
}; };
Service = { Service = {
ExecStart = "${pkgs.wpaperd}/bin/wpaperd --config ${runtimeConf}"; ExecStart = "${pkgs.hyprpaper}/bin/hyprpaper";
Restart = "on-failure"; Restart = "on-failure";
RestartSec = 1; RestartSec = 1;
}; };
Install = { WantedBy = [ "graphical-session.target" ]; };
Install = {
WantedBy = [ "graphical-session.target" ];
};
}; };
# 4) Optional: run your workspace generator once per login, then restart wpaperd systemd.user.services.hyprpaper-workspace-wallpapers = {
systemd.user.services.wpaperd-workspaces-init = {
Unit = { Unit = {
Description = "Generate workspace wallpapers (wpaperd runtime config)"; Description = "Hyprpaper workspace wallpapers (socket2 listener)";
PartOf = [ "graphical-session.target" ]; PartOf = [ "graphical-session.target" ];
After = [ "graphical-session.target" ]; After = [ "graphical-session.target" "hyprpaper.service" ];
}; };
Service = { Service = {
Type = "oneshot"; ExecStart = "${pkgs.bash}/bin/bash ${config.xdg.configHome}/${wsScriptRel} ${picturesDir}";
ExecStart = "${pkgs.bash}/bin/bash ${wsScript} ${picturesDir}"; Restart = "on-failure";
ExecStartPost = "${pkgs.systemd}/bin/systemctl --user restart wpaperd"; RestartSec = 1;
};
Install = {
WantedBy = [ "graphical-session.target" ];
}; };
Install = { WantedBy = [ "graphical-session.target" ]; };
}; };
} }