{ config, pkgs, lib, ... }: with lib; let dbus-sway-environment = pkgs.writeTextFile { name = "dbus-sway-environment"; destination = "/bin/dbus-sway-environment"; executable = true; text = '' dbus-update-activation-environment --systemd WAYLAND_DISPLAY XDG_CURRENT_DESKTOP=sway systemctl --user import-environment DISPLAY export STEAM_RUNTIME=0 ''; }; battery-alert-swaynag = pkgs.writeShellScriptBin "battery-alert-swaynag" '' #!/usr/bin/env bash set -euo pipefail # Detect a battery cap_file="" status_file="" for d in /sys/class/power_supply/BAT*; do if [[ -f "$d/capacity" ]]; then cap_file="$d/capacity" status_file="$d/status" break fi done if [[ -z "$cap_file" ]]; then exit 0 fi capacity=$(cat "$cap_file") status=$(cat "$status_file" 2>/dev/null || echo "Unknown") stamp="/run/user/$(id -u)/.battery_swaynag_stamp" pidfile="/run/user/$(id -u)/.battery_swaynag_pid" if [[ "$capacity" -lt 20 && "$status" != "Charging" && "$status" != "Full" ]]; then now=$(date +%s) last=0 if [[ -f "$stamp" ]]; then last=$(cat "$stamp" 2>/dev/null || echo 0) fi # Avoid spamming: at most once every 5 minutes if (( now - last >= 300 )); then # Kill previous battery swaynag if still running if [[ -f "$pidfile" ]]; then old_pid=$(cat "$pidfile" 2>/dev/null || echo "") if [[ -n "$old_pid" ]] && kill -0 "$old_pid" 2>/dev/null; then kill "$old_pid" 2>/dev/null || true fi fi echo "$now" > "$stamp" swaynag -t warning -m "Battery low: ''${capacity}% - plug in the charger." -b "Dismiss" "true" & echo $! > "$pidfile" disown || true fi else # Charging or battery OK - close any existing warning bar if [[ -f "$pidfile" ]]; then old_pid=$(cat "$pidfile" 2>/dev/null || echo "") if [[ -n "$old_pid" ]] && kill -0 "$old_pid" 2>/dev/null; then kill "$old_pid" 2>/dev/null || true fi rm -f "$pidfile" "$stamp" fi fi ''; sway-conf = builtins.readFile ./sway.conf + '' exec swaybg -m center -c 252525 -i ~/.wallpaper.png ''; in { environment.systemPackages = with pkgs; [ dbus-sway-environment rofi-rbw-wayland swaybg sway-launcher-desktop swayidle swaylock waybar wayland wofi battery-alert-swaynag ]; programs.sway = { enable = true; wrapperFeatures.gtk = true; extraOptions = [ ]; extraSessionCommands = '' export WLR_NO_HARDWARE_CURSORS=1 export WLR_RENDERER=vulkan ''; }; environment.etc = { "sway/config".text = sway-conf; "wofi/style.css".text = builtins.readFile ./wofi.css; "xdg/waybar/config".text = builtins.readFile ./waybar.conf; "xdg/waybar/style.css".text = builtins.readFile ./waybar.css; "xdg/foot/foot.ini".text = builtins.readFile ./foot.ini; # dark mode "xdg/gtk-2.0/gtkrc".text = "gtk-error-bell=0"; "xdg/gtk-3.0/settings.ini".text = '' [Settings] gtk-error-bell=false gtk-application-prefer-dark-theme=1 ''; "xdg/gtk-4.0/settings.ini".text = '' [Settings] gtk-error-bell=false gtk-application-prefer-dark-theme=1 ''; }; }