Files
nixos/hosts/nb/modules/sway/sway.nix

105 lines
2.7 KiB
Nix

{ 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 stop pipewire pipewire-media-session xdg-desktop-portal xdg-desktop-portal-wlr
systemctl --user start pipewire pipewire-media-session xdg-desktop-portal xdg-desktop-portal-wlr
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")
if [[ "$capacity" -lt 20 && "$status" != "Charging" && "$status" != "Full" ]]; then
stamp="/run/user/$(id -u)/.battery_swaynag_stamp"
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
echo "$now" > "$stamp"
swaynag -t warning -m "Battery low: ''${capacity}% - plug in the charger." -b "Dismiss" "true" &
disown || true
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 = [
"--unsupported-gpu"
];
};
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
'';
};
}