{ pkgs, ... }:
{
wayland.windowManager.sway = {
enable = true;
wrapperFeatures.gtk = true; # Fixes common issues with GTK 3 apps
config = rec {
modifier = "Mod4";
# Use kitty as default terminal
terminal = "foot";
keybindings = {
# Brightness Controls
"XF86MonBrightnessDown" = "exec brightnessctl s 5%-";
"XF86MonBrightnessUp" = "exec brightnessctl s 5%+";
# Volume Controls
"XF86AudioRaiseVolume" = "exec pactl set-sink-volume @DEFAULT_SINK@ +1%";
"XF86AudioLowerVolume" = "exec pactl set-sink-volume @DEFAULT_SINK@ -1%";
"XF86AudioMute" = "exec pactl set-sink-mute @DEFAULT_SINK@ toggle";
"Mod4+q" = "kill";
"Mod4+Return" = "exec foot";
"Mod4+Shift+q" = "kill";
"Mod4+d" = "exec wmenu-run";
"Mod4+Left" = "focus left";
"Mod4+Down" = "focus down";
"Mod4+Up" = "focus up";
"Mod4+Right" = "focus right";
"Mod4+Shift+Left" = "move left";
"Mod4+Shift+Down" = "move down";
"Mod4+Shift+Up" = "move up";
"Mod4+Shift+Right" = "move right";
"Mod4+b" = "splith";
"Mod4+v" = "splitv";
"Mod4+f" = "fullscreen toggle";
"Mod4+a" = "focus parent";
"Mod4+s" = "layout stacking";
"Mod4+w" = "layout tabbed";
"Mod4+e" = "layout toggle split";
"Mod4+Shift+space" = "floating toggle";
"Mod4+space" = "focus mode_toggle";
"Mod4+1" = "workspace number 1";
"Mod4+2" = "workspace number 2";
"Mod4+3" = "workspace number 3";
"Mod4+4" = "workspace number 4";
"Mod4+5" = "workspace number 5";
"Mod4+6" = "workspace number 6";
"Mod4+7" = "workspace number 7";
"Mod4+8" = "workspace number 8";
"Mod4+9" = "workspace number 9";
"Mod4+0" = "workspace number 10";
"Mod4+Shift+1" = "move container to workspace number 1";
"Mod4+Shift+2" = "move container to workspace number 2";
"Mod4+Shift+3" = "move container to workspace number 3";
"Mod4+Shift+4" = "move container to workspace number 4";
"Mod4+Shift+5" = "move container to workspace number 5";
"Mod4+Shift+6" = "move container to workspace number 6";
"Mod4+Shift+7" = "move container to workspace number 7";
"Mod4+Shift+8" = "move container to workspace number 8";
"Mod4+Shift+9" = "move container to workspace number 9";
"Mod4+Shift+0" = "move container to workspace number 10";
"Mod4+Shift+minus" = "move scratchpad";
"Mod4+minus" = "scratchpad show";
"Mod4+p" = "[app_id=\"trilium\"] scratchpad show, resize set 90 ppt 90 ppt, move position center";
"Mod4+g" = "exec glide-browser";
"Mod4+Shift+i" = "exec makoctl invoke && makoctl dismiss";
"Mod4+i" = "exec makoctl dismiss";
"Mod4+Shift+c" = "reload";
"Mod4+Shift+e" =
"exec swaynag -t warning -m 'You pressed the exit shortcut. Do you really want to exit sway? This will end your Wayland session.' -b 'Yes, exit sway' 'swaymsg exit'";
"Mod4+r" = "mode resize";
"Mod4+c" = "[app_id=\"discord\"] scratchpad show, resize set 90 ppt 90 ppt, move position center";
"Mod4+j" = "[class=\"Jami\"] scratchpad show, resize set 90 ppt 90 ppt, move position center";
"Print" = "exec flameshot gui";
};
bars = [
{
command = "${pkgs.waybar}/bin/waybar";
}
];
output = {
eDP-1 = {
scale = "1.25";
};
};
input = {
"type:touchpad" = {
# Enables or disables tap for specified input device.
tap = "enabled";
# Enables or disables natural (inverted) scrolling for the specified input device.
natural_scroll = "enabled";
# Enables or disables disable-while-typing for the specified input device.
dwt = "disabled";
};
};
bindswitches = {
"lid:on" = {
reload = true;
locked = true;
action = "exec systemctl suspend-then-hibernate";
};
};
startup = [
# { command = "swaybg -i ~/.background-image -m fill"; }
{ command = "discord --enable-features=UseOzonePlatform --ozone-platform=wayland"; }
{ command = "trilium"; }
{ command = "jami"; }
];
window.commands = [
{
criteria = {
app_id = "discord";
};
command = "move scratchpad";
}
{
criteria = {
app_id = "trilium";
};
command = "move scratchpad";
}
{
criteria = {
class = "Jami";
};
command = "move scratchpad";
}
];
};
extraConfig = ''
exec_always swaymsg output "*" bg ~/.background-image fit
'';
};
# 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" fit
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 = {
enable = true;
style = ./waybar.css;
settings = {
mainBar = {
layer = "top";
position = "bottom"; # Puts the bar at the bottom
height = 30;
# Define what goes where on the bar
modules-left = [
"sway/workspaces"
"sway/mode"
];
modules-center = [ "sway/window" ];
modules-right = [
"backlight"
"pulseaudio"
"battery"
"clock"
"tray"
];
backlight = {
format = "{icon} {percent}%";
format-icons = [
"đ"
"đ"
"đ"
"đ"
"đ"
];
};
pulseaudio = {
format = "{icon} {volume}%";
format-muted = "đ Muted";
format-icons = {
default = [
"đ"
"đ"
"đ"
];
};
scroll-step = 1;
on-click = "pactl set-sink-mute @DEFAULT_SINK@ toggle";
};
clock = {
format = "{:%Y-%m-%d %H:%M}";
tooltip-format = "{:%Y %B}\n{calendar}";
};
battery = {
states = {
warning = 30;
critical = 15;
};
format = "{icon} {capacity}% ({time})";
format-charging = "⥠{capacity}% ({time})";
format-plugged = "đ {capacity}% ({time})";
format-icons = [
"đĒĢ"
"đ"
"đ"
"đ"
"đ"
];
};
};
};
};
services.swayidle.events = {
"before-sleep" = "${pkgs.swaylock}/bin/swaylock -fF";
};
services.swayidle.enable = true;
# Configure Qt to use kvantum theming
qt = {
enable = true;
platformTheme.name = "org.kde.breezedark.desktop";
style = {
name = "org.kde.breezedark.desktop";
};
};
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
];
# Environment variables for kvantum theming
home.sessionVariables = {
QT_QPA_PLATFORMTHEME = "org.kde.breezedark.desktop";
QT_STYLE_OVERRIDE = "org.kde.breezedark.desktop";
GTK_THEME = "Materia-dark-compact";
};
}