From 02d9349a03f561b52aadf40dc55e81985dd2df0f Mon Sep 17 00:00:00 2001 From: Filippo Berto Date: Fri, 16 Jan 2026 14:13:58 +0100 Subject: [PATCH] Fix hyprland background --- hm/hyprland.nix | 2 +- hm/wl_update_background.nix | 11 ++++++-- pkgs/wl-update-background/default.nix | 40 ++++++++++----------------- 3 files changed, 24 insertions(+), 29 deletions(-) diff --git a/hm/hyprland.nix b/hm/hyprland.nix index 724a7d6..119859b 100644 --- a/hm/hyprland.nix +++ b/hm/hyprland.nix @@ -229,7 +229,7 @@ in "SUPER, J, togglesplit, # dwindle" "SUPER ALT, E, exec, wofi-emoji" "SUPER ALT, P, exec, wl-clipedit" - "SUPER ALT, B, exec, wl-update-background" + "SUPER ALT, B, exec, systemctl --user reload-or-restart wl-update-background" ",Print, exec, grimblast copy" "SHIFT, Print, exec, grimblast copy area" diff --git a/hm/wl_update_background.nix b/hm/wl_update_background.nix index 0ab50e5..d4955dd 100644 --- a/hm/wl_update_background.nix +++ b/hm/wl_update_background.nix @@ -1,4 +1,9 @@ -{ pkgs, ... }: { +{ pkgs, nixosConfig, ... }: +let + inherit (nixosConfig.networking) hostName; + backgrounds_directory = if hostName == "sif" then "$HOME/Pictures/Wallpapers/2160+" else "$HOME/Immagini/Sfondi/2160+"; +in +{ home.packages = [ pkgs.wl-update-background ]; systemd.user.services."wl-update-background" = { @@ -6,7 +11,6 @@ Description = "Set random desktop background using swww"; After = [ "graphical-session.pre.target" ]; PartOf = [ "graphical-session.target" ]; - RequiresMountsFor = [ "/home/bertof/Immagini" ]; }; Install = { WantedBy = [ "graphical-session.target" ]; @@ -14,7 +18,8 @@ Service = { Type = "oneshot"; IOSchedulingClass = "idle"; - ExecStart = "${pkgs.wl-update-background}/bin/wl-update-background"; + StartLimitBurst = 0; + ExecStart = "${pkgs.wl-update-background.override {inherit backgrounds_directory;}}/bin/wl-update-background"; }; }; diff --git a/pkgs/wl-update-background/default.nix b/pkgs/wl-update-background/default.nix index 5dc1470..dcc26ad 100644 --- a/pkgs/wl-update-background/default.nix +++ b/pkgs/wl-update-background/default.nix @@ -1,29 +1,19 @@ -{ findutils -, coreutils -, writeShellScriptBin +{ coreutils +, findutils , hyprland +, lib +, writeShellScriptBin , backgrounds_directory ? "$HOME/Immagini/Sfondi/" -}: writeShellScriptBin "wl-update-background" +}: writeShellScriptBin "wl-update-background" '' + set -euo pipefail + PATH=$PATH:${lib.makeBinPath [findutils coreutils hyprland]} + WALLPAPER_DIR=${backgrounds_directory} + CURRENT_WALL=$(hyprctl hyprpaper listloaded) + CURRENT_WALL=$(basename "$CURRENT_WALL") - # '' - # set -e - # if [ $# -eq 0 ]; then - # image=`${findutils}/bin/find ${backgrounds_directory} -type f | ${gnugrep}/bin/grep -v "/\." | ${coreutils}/bin/shuf -n 1` - # else - # image="$1" - # fi - # echo "image: $image" - # ${swww}/bin/swww img "$image" - # '' + # Get a random wallpaper that is not the current one + NEW_WALLPAPER=$(find "$WALLPAPER_DIR" -type f ! -name "$CURRENT_WALL" | shuf -n 1) - '' - set -euo pipefail - WALLPAPER_DIR=${backgrounds_directory} - CURRENT_WALL=$(hyprctl hyprpaper listloaded) - - # Get a random wallpaper that is not the current one - WALLPAPER=$(${findutils}/bin/find "$WALLPAPER_DIR" -type f ! -name "$(${coreutils}/bin/basename "$CURRENT_WALL")" | ${coreutils}/bin/shuf -n 1) - - # Apply the selected wallpaper - ${hyprland}/bin/hyprctl hyprpaper reload ,"$WALLPAPER" - '' + # Apply the selected wallpaper + hyprctl hyprpaper reload ,"$NEW_WALLPAPER" +''