random bg (ty gemini)
This commit is contained in:
@@ -63,7 +63,7 @@
|
||||
|
||||
# Define time delay for hibernation
|
||||
systemd.sleep.settings.Sleep = {
|
||||
HibernateDelaySec = 900;
|
||||
HibernateDelaySec = 300;
|
||||
};
|
||||
|
||||
# facial recognition
|
||||
|
||||
@@ -114,7 +114,7 @@
|
||||
};
|
||||
};
|
||||
startup = [
|
||||
{ command = "swaybg -i ~/.background-image -m fill"; }
|
||||
# { command = "swaybg -i ~/.background-image -m fill"; }
|
||||
{ command = "discord --enable-features=UseOzonePlatform --ozone-platform=wayland"; }
|
||||
{ command = "trilium"; }
|
||||
{ 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 = {
|
||||
@@ -237,4 +304,5 @@
|
||||
QT_STYLE_OVERRIDE = "org.kde.breezedark.desktop";
|
||||
GTK_THEME = "Materia-dark-compact";
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user