Files
nixos/OLD CONFIGS/nix_old/modules/home-manager/backgrounds.nix
T
2026-02-22 19:25:39 +01:00

98 lines
2.7 KiB
Nix
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
{ config, lib, pkgs, ... }:
let
moduleName = "hm-backgrounds";
src = ../home-manager/conf/backgrounds;
video = "${config.home.homeDirectory}/backgrounds/videos/191684-891315375.mp4";
startWallpaper = pkgs.writeShellScript "start-video-wallpaper" ''
set -euo pipefail
VIDEO="${video}"
MPVPAPER="${pkgs.mpvpaper}/bin/mpvpaper"
HYPRCTL="${pkgs.hyprland}/bin/hyprctl"
PKILL="${pkgs.procps}/bin/pkill"
AWK="${pkgs.gawk}/bin/awk"
# Avoid stacking multiple instances on rebuild / relogin
$PKILL -x mpvpaper || true
# Wait until Hyprland is ready
for i in $(seq 1 30); do
if $HYPRCTL monitors >/dev/null 2>&1; then
break
fi
sleep 1
done
# If the file doesn't exist, don't crash-loop forever
if [ ! -f "$VIDEO" ]; then
echo "Wallpaper video not found: $VIDEO"
exit 0
fi
# Detect monitors
MONITORS="$($HYPRCTL monitors | $AWK '/^Monitor/ {print $2}')"
if [ -z "$MONITORS" ]; then
echo "No monitors detected by hyprctl."
exit 0
fi
# Start mpvpaper per monitor
for m in $MONITORS; do
$MPVPAPER -o "--loop --no-audio --panscan=1.0 --video-aspect-override=yes" "$m" "$VIDEO" &
done
wait
'';
in
{
# 0) Make HM reliably manage/restart user services on switch
# (prevents having to run systemctl --user daemon-reload manually)
systemd.user.startServices = "sd-switch";
# 1) Put the whole repo folder into ~/backgrounds
home.file."backgrounds".source = src;
# 2) Ensure dependencies exist
home.packages = with pkgs; [
mpv
mpvpaper
procps
gawk
];
# 3) Run video wallpaper on ALL monitors
#
# IMPORTANT:
# - Do NOT tie to graphical-session.target / hyprland-session.target, because in your setup
# those targets were inactive/missing.
# - Instead, start on user login via default.target, and the script itself waits for Hyprland.
systemd.user.services.video-wallpaper = {
Unit = {
Description = "Video wallpaper (mpvpaper) on all Hyprland monitors";
};
Service = {
Type = "simple";
Restart = "on-failure";
RestartSec = 2;
ExecStart = startWallpaper;
};
Install = {
WantedBy = [ "default.target" ];
};
};
# 4) Restart on switch so new /nix/store script paths are picked up
# (kept, but now it wont break boot/login if the user bus isnt ready)
home.activation.restartVideoWallpaper =
lib.hm.dag.entryAfter [ "writeBoundary" ] ''
${pkgs.systemd}/bin/systemctl --user daemon-reload || true
${pkgs.systemd}/bin/systemctl --user reset-failed video-wallpaper || true
${pkgs.systemd}/bin/systemctl --user restart video-wallpaper || true
'';
home.file.".nixlog/loaded.${moduleName}-module-loaded".text = "loaded\n";
}