random bg (ty gemini)

This commit is contained in:
TheCrazyInsanity
2026-04-15 12:40:34 -04:00
parent 0b3b7c1822
commit 43020e5b51
2 changed files with 70 additions and 2 deletions

View File

@@ -63,7 +63,7 @@
# Define time delay for hibernation # Define time delay for hibernation
systemd.sleep.settings.Sleep = { systemd.sleep.settings.Sleep = {
HibernateDelaySec = 900; HibernateDelaySec = 300;
}; };
# facial recognition # facial recognition

View File

@@ -114,7 +114,7 @@
}; };
}; };
startup = [ startup = [
{ command = "swaybg -i ~/.background-image -m fill"; } # { command = "swaybg -i ~/.background-image -m fill"; }
{ command = "discord --enable-features=UseOzonePlatform --ozone-platform=wayland"; } { command = "discord --enable-features=UseOzonePlatform --ozone-platform=wayland"; }
{ command = "trilium"; } { command = "trilium"; }
{ command = "jami"; } { command = "jami"; }
@@ -140,6 +140,73 @@
} }
]; ];
}; };
extraConfig = ''
exec_always swaymsg output "*" bg ~/.background-image fill
'';
};
# yeah this was written by ai if it wasn't obvious
systemd.user.services.random-background = {
Unit = {
Description = "Update ~/.background_image with a random wallpaper";
};
Service = {
Type = "oneshot";
# pkgs.writeShellScript creates an executable script in the nix store
ExecStart = "${pkgs.writeShellScript "random-bg-script" ''
# Nix uses 'set -e' by default, meaning any command failure kills the script.
# We use native bash features to safely handle finding the image and socket.
WALLPAPER_DIR="$HOME/wallpapers"
TARGET="$HOME/.background_image"
if [ ! -d "$WALLPAPER_DIR" ]; then
echo "Wallpaper directory not found."
exit 0
fi
# 1. Get a random image safely (|| true prevents set -e crashes if find returns nothing)
RANDOM_IMG=$(${pkgs.findutils}/bin/find "$WALLPAPER_DIR" -type f \( -iname \*.jpg -o -iname \*.png -o -iname \*.jpeg \) 2>/dev/null | ${pkgs.coreutils}/bin/shuf -n 1 || true)
if [ -n "$RANDOM_IMG" ]; then
# 2. Update symlink
${pkgs.coreutils}/bin/ln -sf "$RANDOM_IMG" "$TARGET"
# 3. Safely find the socket using native Bash globbing.
# systemd user services natively provide the correct $XDG_RUNTIME_DIR (/run/user/1000)
shopt -s nullglob
SOCKETS=("$XDG_RUNTIME_DIR"/sway-ipc.*.sock)
# 4. Check if the bash array found any socket files
if [ ''${#SOCKETS[@]} -gt 0 ]; then
export SWAYSOCK="''${SOCKETS[0]}"
echo "Using socket: $SWAYSOCK"
# 5. Execute swaymsg
${pkgs.sway}/bin/swaymsg output "*" bg "$RANDOM_IMG" fill
echo "Updated background to $RANDOM_IMG"
else
echo "Error: Could not find any sway socket in $XDG_RUNTIME_DIR"
exit 1
fi
else
echo "No images found in $WALLPAPER_DIR"
fi
''}";
};
};
systemd.user.timers.random-background = {
Unit = {
Description = "Run random-background service every hour";
};
Timer = {
OnCalendar = "minutely";
Persistent = true;
};
Install = {
WantedBy = [ "timers.target" ];
};
}; };
programs.waybar = { programs.waybar = {
@@ -237,4 +304,5 @@
QT_STYLE_OVERRIDE = "org.kde.breezedark.desktop"; QT_STYLE_OVERRIDE = "org.kde.breezedark.desktop";
GTK_THEME = "Materia-dark-compact"; GTK_THEME = "Materia-dark-compact";
}; };
} }