diff --git a/machines/latitude/configuration.nix b/machines/latitude/configuration.nix index 5c225b5..5e8de3e 100755 --- a/machines/latitude/configuration.nix +++ b/machines/latitude/configuration.nix @@ -6,6 +6,7 @@ config, lib, pkgs, + inputs, ... }: { @@ -87,9 +88,9 @@ # List packages installed in system profile. # You can use https://search.nixos.org/ to find more packages (and options). - #environment.systemPackages = with pkgs; [ - # cura-appimage # I want cura but not kicad so i dont pull in fabrication - # ]; + environment.systemPackages = [ + inputs.llm-agents.packages.${pkgs.stdenv.hostPlatform.system}.pi + ]; # Some programs need SUID wrappers, can be configured further or are # started in user sessions. diff --git a/modules/sway/default.nix b/modules/sway/default.nix index 4fa3209..d1041e2 100644 --- a/modules/sway/default.nix +++ b/modules/sway/default.nix @@ -52,7 +52,6 @@ in pkgs.wmenu pkgs.wl-clipboard pkgs.mako - pkgs.kdePackages.spectacle pkgs.kdePackages.kate pkgs.kdePackages.filelight inputs.glide.packages.${pkgs.stdenv.hostPlatform.system}.default @@ -62,6 +61,7 @@ in pkgs.dracula-theme # gtk theme pkgs.brightnessctl configure-gtk + pkgs.mpvpaper ]; }; diff --git a/modules/sway/home.nix b/modules/sway/home.nix index a0a4e9f..640e887 100644 --- a/modules/sway/home.nix +++ b/modules/sway/home.nix @@ -85,6 +85,7 @@ "Mod4+j" = "[class=\"Jami\"] scratchpad show, resize set 90 ppt 90 ppt, move position center"; + "Print" = "exec flameshot gui"; }; bars = [ { @@ -140,72 +141,101 @@ } ]; }; - 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"; + Description = "Universal Wallpaper Rotator (Images, GIFs, Videos)"; + After = [ "graphical-session.target" ]; + PartOf = [ "graphical-session.target" ]; }; - 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" ]; + WantedBy = [ "graphical-session.target" ]; + }; + + Service = { + Type = "simple"; + Restart = "on-failure"; + RestartSec = 5; + + ExecStart = "${pkgs.writeShellScript "wallpaper-rotator" '' + WALLPAPER_DIR="$HOME/wallpapers" + INTERVAL=600 # Time in seconds between wallpaper changes (600 = 10 mins) + + # 1. Safely find Wayland and Sway sockets + if [ -z "$WAYLAND_DISPLAY" ]; then + shopt -s nullglob + W_SOCKETS=("$XDG_RUNTIME_DIR"/wayland-[0-9]*) + if [ ''${#W_SOCKETS[@]} -gt 0 ]; then + export WAYLAND_DISPLAY=$(basename "''${W_SOCKETS[0]}") + fi + fi + + if [ -z "$SWAYSOCK" ]; then + shopt -s nullglob + S_SOCKETS=("$XDG_RUNTIME_DIR"/sway-ipc.*.sock) + if [ ''${#S_SOCKETS[@]} -gt 0 ]; then + export SWAYSOCK="''${S_SOCKETS[0]}" + fi + fi + + # State tracking for mpvpaper + MPV_PID="" + + # Clean up mpvpaper gracefully if systemd stops the service + cleanup() { + if [ -n "$MPV_PID" ]; then + kill $MPV_PID 2>/dev/null || true + fi + exit 0 + } + trap cleanup SIGINT SIGTERM + + # 2. Infinite rotation loop + while true; do + if [ ! -d "$WALLPAPER_DIR" ]; then + echo "Wallpaper directory not found. Waiting..." + ${pkgs.coreutils}/bin/sleep 60 + continue + fi + + # Find images, gifs, and videos + MEDIA=$(${pkgs.findutils}/bin/find "$WALLPAPER_DIR" -type f \( \ + -iname \*.jpg -o -iname \*.jpeg -o -iname \*.png -o \ + -iname \*.mp4 -o -iname \*.webm -o -iname \*.mkv -o -iname \*.gif \ + \) 2>/dev/null | ${pkgs.coreutils}/bin/shuf -n 1 || true) + + if [ -n "$MEDIA" ]; then + echo "Selected: $MEDIA" + EXT="''${MEDIA##*.}" + EXT=$(echo "$EXT" | tr '[:upper:]' '[:lower:]') # Convert to lowercase + + # If it's a static image, use Sway directly (saves battery/RAM) + if [[ "$EXT" == "jpg" || "$EXT" == "jpeg" || "$EXT" == "png" ]]; then + if [ -n "$MPV_PID" ]; then + kill $MPV_PID 2>/dev/null || true + MPV_PID="" + fi + ${pkgs.sway}/bin/swaymsg output "*" bg "$MEDIA" fill + + # If it's a video/gif, use mpvpaper + else + if [ -n "$MPV_PID" ]; then + kill $MPV_PID 2>/dev/null || true + fi + # Start mpvpaper in the background and record its process ID + ${pkgs.mpvpaper}/bin/mpvpaper -o "loop no-audio" "*" "$MEDIA" & + MPV_PID=$! + fi + else + echo "No media found in $WALLPAPER_DIR." + fi + + # Wait for the next rotation + ${pkgs.coreutils}/bin/sleep $INTERVAL + done + ''}"; }; }; @@ -293,6 +323,21 @@ }; }; + services.flameshot = { + # Also installs/enables flameshot + enable = true; + settings = { + General = { + useGrimAdapter = true; + # Stops warnings for using Grim + disabledGrimWarning = true; + uiColor = "#00ff73"; + contrastUiColor = "#002f01"; + drawColor = "#ff0000"; + }; + }; + }; + # Install packages for better Qt support and kvantum themes home.packages = with pkgs; [ kdePackages.breeze