nixos_config/home/wm/sway.nix

509 lines
17 KiB
Nix
Raw Normal View History

2025-08-24 16:05:54 +02:00
{ pkgs, config, hostName, lib, ... }:
let
# execs
2026-01-19 18:22:45 +01:00
uwsm = "${pkgs.uwsm}/bin/uwsm-app --";
2025-12-02 21:38:59 +01:00
swaymsg = "${pkgs.sway}/bin/swaymsg";
2025-08-24 16:05:54 +02:00
lock = "${pkgs.swaylock}/bin/swaylock --daemonize";
2025-12-02 21:38:59 +01:00
term = "${pkgs.kitty}/bin/kitty";
notify = "${pkgs.libnotify}/bin/notify-send";
2026-01-07 19:19:47 +01:00
nag = "${pkgs.sway}/bin/swaynag --edge bottom";
2026-01-19 18:22:45 +01:00
dmenu = "${pkgs.rofi-unwrapped}/bin/rofi";
2026-01-28 18:24:25 +01:00
espanso = "${pkgs.espanso-wayland}/bin/espanso cmd";
2025-08-24 16:05:54 +02:00
# keybinds
2025-12-09 16:34:37 +01:00
key_mod = "Mod4";
key_mod_misc = "Alt";
2025-08-24 16:05:54 +02:00
key_left = "Left";
key_right = "Right";
key_up = "Up";
key_down = "Down";
# other
2025-12-02 21:38:59 +01:00
display = status: "${swaymsg} 'output * power ${status}'";
2025-12-02 19:21:57 +01:00
hostnameOutput =
if hostName == "tower" then {
# Left monitor
DP-1 = {
mode = "1920x1080@143.981Hz";
transform = "90";
position = "0 0";
};
# Main monitor
DP-2 = {
mode = "3440x1440@99.982Hz";
position = "1080 250";
};
# Right monitor
DP-3 = {
mode = "1920x1080@143.981Hz";
position = "4520 250";
};
}
else if hostName == "electra" then {}
else {};
hostnameWorkspaceAssign =
if hostName == "tower" then [
{ output = "DP-2"; workspace = "1"; }
2025-12-06 23:47:07 +01:00
{ output = "DP-2"; workspace = "2"; }
{ output = "DP-2"; workspace = "3"; }
{ output = "DP-3"; workspace = "4"; }
2025-12-02 19:21:57 +01:00
{ output = "DP-3"; workspace = "5"; }
2025-12-06 23:47:07 +01:00
{ output = "DP-3"; workspace = "6"; }
{ output = "DP-1"; workspace = "7"; }
{ output = "DP-1"; workspace = "8"; }
2025-12-02 19:21:57 +01:00
{ output = "DP-1"; workspace = "9"; }
]
else if hostName == "electra" then []
else [];
hostnameServices =
if hostName == "tower" then {}
else if hostName == "electra" then {
swayidle = {
enable = true;
timeouts = [
{
timeout = 120;
2025-12-02 21:38:59 +01:00
command = "${notify} 'Locking in 5 seconds' -t 5000";
2025-12-02 19:21:57 +01:00
}
{
timeout = 125;
command = lock;
}
{
timeout = 125;
command = display "off";
resumeCommand = display "on";
}
{
timeout = 600;
command = "${pkgs.systemd}/bin/systemctl suspend";
}
]; # end timeouts
events = [
{
event = "before-sleep";
2025-12-02 21:38:59 +01:00
command = "display off; systemctl --user stop libinput-gestures; ${lock}";
2025-12-02 19:21:57 +01:00
}
{
event = "after-resume";
command = "display on; systemctl --user start libinput-gestures";
}
{
event = "lock";
command = (display "off") + "; " + lock;
}
{
event = "unlock";
command = display "on";
}
]; # end events
}; # end swayidle
2025-12-10 21:45:04 +01:00
}
2025-12-02 19:21:57 +01:00
else {};
hostnameInput1 =
if hostName == "tower" then "us"
else "se";
hostnameInput2 =
if hostName == "tower" then "se"
else "us";
2025-08-24 16:05:54 +02:00
in
{
2025-08-24 16:05:54 +02:00
wayland.windowManager.sway = {
enable = true;
2025-12-11 20:23:32 +01:00
wrapperFeatures.gtk = true;
2025-08-24 16:05:54 +02:00
config = {
modifier = "${key_mod}";
2025-12-01 22:40:14 +01:00
startup = [
2025-12-02 19:21:57 +01:00
{ command = "systemctl --user start libinput-gestures"; }
2026-01-19 18:22:45 +01:00
{ command = ''${uwsm} swaybg -m fill -i /home/alisceon/Pictures/system/bg.png'';}
2025-12-01 22:40:14 +01:00
];
2026-01-19 18:22:45 +01:00
bars = [ ];
2025-08-24 16:05:54 +02:00
input = {
"type:touchpad" = {
dwt = "enabled";
tap = "enabled";
natural_scroll = "disabled";
middle_emulation = "enabled";
click_method = "clickfinger";
clickfinger_button_map = "lrm";
scroll_factor = "0.6";
2025-08-24 16:05:54 +02:00
};
"type:mouse" = {
natural_scroll = "disabled";
2025-12-04 15:40:58 +01:00
accel_profile = "flat";
2026-01-08 18:05:08 +01:00
pointer_accel = "0.5";
2025-08-24 16:05:54 +02:00
};
"*" = {
xkb_layout = "${hostnameInput1},${hostnameInput2}";
2025-12-04 15:40:58 +01:00
xkb_options = "grp:win_space_toggle";
2025-08-24 16:05:54 +02:00
};
}; # end input
keybindings = {
# Workspaces
2025-12-01 22:40:14 +01:00
"${key_mod}+f" = "fullscreen";
2025-12-05 19:48:03 +01:00
"${key_mod}+Shift+f" = "floating toggle";
2025-08-24 16:05:54 +02:00
"${key_mod}+1" = "workspace number 1";
"${key_mod}+2" = "workspace number 2";
"${key_mod}+3" = "workspace number 3";
"${key_mod}+4" = "workspace number 4";
"${key_mod}+5" = "workspace number 5";
"${key_mod}+6" = "workspace number 6";
"${key_mod}+7" = "workspace number 7";
"${key_mod}+8" = "workspace number 8";
"${key_mod}+9" = "workspace number 9";
2025-12-01 22:40:14 +01:00
"${key_mod}+0" = "scratchpad show";
2025-08-24 16:05:54 +02:00
"${key_mod}+Shift+1" = "move container to workspace number 1; workspace 1";
"${key_mod}+Shift+2" = "move container to workspace number 2; workspace 2";
"${key_mod}+Shift+3" = "move container to workspace number 3; workspace 3";
"${key_mod}+Shift+4" = "move container to workspace number 4; workspace 4";
"${key_mod}+Shift+5" = "move container to workspace number 5; workspace 5";
"${key_mod}+Shift+6" = "move container to workspace number 6; workspace 6";
"${key_mod}+Shift+7" = "move container to workspace number 7; workspace 7";
"${key_mod}+Shift+8" = "move container to workspace number 8; workspace 8";
"${key_mod}+Shift+9" = "move container to workspace number 9; workspace 9";
2025-12-01 22:40:14 +01:00
"${key_mod}+Shift+0" = "move container to scratchpad; scratchpad show";
"${key_mod}+Ctrl+1" = "move container to workspace number 1";
"${key_mod}+Ctrl+2" = "move container to workspace number 2";
"${key_mod}+Ctrl+3" = "move container to workspace number 3";
"${key_mod}+Ctrl+4" = "move container to workspace number 4";
"${key_mod}+Ctrl+5" = "move container to workspace number 5";
"${key_mod}+Ctrl+6" = "move container to workspace number 6";
"${key_mod}+Ctrl+7" = "move container to workspace number 7";
"${key_mod}+Ctrl+8" = "move container to workspace number 8";
"${key_mod}+Ctrl+9" = "move container to workspace number 9";
"${key_mod}+Ctrl+0" = "move container to scratchpad";
2025-08-24 16:05:54 +02:00
# Focus
"${key_mod}+${key_left}" = "focus left";
2025-12-06 23:47:07 +01:00
"${key_mod}+${key_right}" = "focus right";
2025-08-24 16:05:54 +02:00
"${key_mod}+${key_down}" = "focus down";
"${key_mod}+${key_up}" = "focus up";
2025-12-06 23:47:07 +01:00
# Move
2025-08-24 16:05:54 +02:00
"${key_mod}+Shift+${key_left}" = "move left";
"${key_mod}+Shift+${key_down}" = "move down";
"${key_mod}+Shift+${key_up}" = "move up";
"${key_mod}+Shift+${key_right}" = "move right";
2025-12-06 23:47:07 +01:00
# Sparkly alt-tab
"${key_mod}+Tab" = "focus right";
"${key_mod}+Shift+Tab" = "focus left";
"${key_mod}+Ctrl+Tab" = "move right";
"${key_mod}+Ctrl+Shift+Tab" = "move left";
2025-12-09 16:34:37 +01:00
"${key_mod}+${key_mod_misc}+Tab" = "workspace next";
"${key_mod}+${key_mod_misc}+Shift+Tab" = "workspace prev";
2025-12-06 23:47:07 +01:00
2025-08-24 16:05:54 +02:00
# System
2025-12-07 12:36:40 +01:00
"Mod4+space" = ''exec ${notify} -t 2000 "$(xonsh ~/.nixos_config/util/get_xkb.xsh)"'';
2025-12-11 20:23:32 +01:00
"${key_mod}+Shift+r" = "reload";
"${key_mod}+Ctrl+r" = "restart";
2025-12-20 13:50:35 +01:00
"${key_mod}+Shift+Backspace" = "exec ${nag} -m 'TuneD profiles:' -Z 'Performance' 'tuned-adm profile accelerator-performance' -Z 'Balanced' 'tuned-adm profile balanced' -Z 'Power Save' 'tuned-adm profile powersave'";
2025-12-11 20:23:32 +01:00
"${key_mod}+Shift+q" = "kill";
2025-12-20 13:50:35 +01:00
"Alt+F4" = "kill";
2025-12-11 20:23:32 +01:00
# Locking and idle
"${key_mod}+L" = "exec ${lock}";
2026-01-19 18:22:45 +01:00
"${key_mod}+Escape" = "exec ${nag} -m 'Shutdown options:' -Z 'Power Off' 'systemctl poweroff' -Z 'Reboot' 'systemctl reboot' -Z 'Logout' 'swaymsg exit'";
2025-12-11 20:23:32 +01:00
# Apps
2026-01-19 18:22:45 +01:00
"${key_mod}+Return" = ''exec "${uwsm} ${term}"'';
"${key_mod}+d" = ''exec "${uwsm} ${dmenu} -show drun"'';
2026-01-28 18:24:25 +01:00
"${key_mod}+e" = ''exec "${uwsm} ${espanso} search"'';
"${key_mod}+Shift+e" = ''exec "${uwsm} ${espanso} toggle"'';
2026-01-19 18:22:45 +01:00
2025-12-11 20:23:32 +01:00
2026-01-19 18:22:45 +01:00
# Screenshot region
2025-12-02 19:21:57 +01:00
"${key_mod}+Shift+s" = "exec grimshot savecopy area";
2025-12-11 20:23:32 +01:00
"${key_mod}+Ctrl+s" = "exec grimshot savecopy output";
2025-12-04 15:40:58 +01:00
# media keys
2025-12-01 22:40:14 +01:00
"XF86AudioRaiseVolume" = "exec 'pactl set-sink-volume @DEFAULT_SINK@ +3%'";
"XF86AudioLowerVolume" = "exec 'pactl set-sink-volume @DEFAULT_SINK@ -3%'";
2025-08-24 16:05:54 +02:00
"XF86AudioMute" = "exec 'pactl set-sink-mute @DEFAULT_SINK@ toggle'";
2025-12-04 15:40:58 +01:00
"XF86AudioPlay" = "exec 'playerctl play-pause'";
2025-12-10 21:45:04 +01:00
"XF86MonBrightnessUp" = "exec ${pkgs.light}/bin/light -A 9";
"XF86MonBrightnessDown" = "exec ${pkgs.light}/bin/light -U 3";
2025-08-24 16:05:54 +02:00
}; # end keybindings
window = {
titlebar = false;
2025-12-10 21:43:34 +01:00
commands = [
2025-12-11 20:23:32 +01:00
{ criteria = { all = true; }; command = "inhibit_idle fullscreen"; }
2025-12-10 21:43:34 +01:00
];
2026-01-07 19:19:47 +01:00
}; # end window
2025-12-02 19:21:57 +01:00
assigns = {
2026-01-08 18:05:08 +01:00
"1" = [{app_id = "chromium";}];
2025-12-06 23:47:07 +01:00
"2" = [{class = "steam";}];
"3" = [];
"4" = [{class = "Code";}];
2025-12-02 21:38:59 +01:00
"5" = [{app_id = "obsidian";}];
2025-12-06 23:47:07 +01:00
"6" = [];
"7" = [];
"8" = [{app_id = "discord";}];
"9" = [{app_id = "signal";}];
2025-12-02 19:21:57 +01:00
};
output = {} // hostnameOutput;
workspaceOutputAssign = hostnameWorkspaceAssign;
2025-08-24 16:05:54 +02:00
};
};
services = {
2026-01-28 18:24:25 +01:00
espanso = {
enable = true;
waylandSupport = true;
configs = {
default = {
toggle_key = "OFF";
preserve_clipboard = true;
show_notifications = true;
keyboard_layout = { layout="${hostnameInput1}"; };
2026-01-28 18:24:25 +01:00
};
};
matches = {
base = {
matches = [
{
trigger = ":ip ";
replace = "{{pubip}} ";
2026-01-28 18:24:25 +01:00
}
{
regex = ":em(?P<emname>\\S+) ";
replace = "{{emoji}} ";
2026-01-28 18:24:25 +01:00
vars = [
{
name = "emoji";
type = "shell";
params = {
cmd = "${pkgs.python3}/bin/python3 /home/alisceon/.nixos_config/util/get_emoji.py $ESPANSO_EMNAME";
};
}
];
}
];
};
global_vars = {
global_vars = [
{
name = "pubip";
type = "shell";
params = {
cmd = "curl -s https://ifconfig.me";
};
}
];
};
};
};
2025-08-25 10:01:53 +02:00
mako = {
enable = true;
settings = {
actions = true;
2025-12-04 15:40:58 +01:00
anchor = "top-center";
2025-08-25 10:01:53 +02:00
border-radius = 0;
2025-12-04 15:40:58 +01:00
default-timeout = 10000;
2025-08-25 10:01:53 +02:00
height = 100;
2025-12-04 15:40:58 +01:00
width = 600;
2025-08-25 10:01:53 +02:00
icons = true;
ignore-timeout = false;
2025-12-04 15:40:58 +01:00
layer = "overlay";
2025-08-25 10:01:53 +02:00
margin = 10;
markup = true;
}; #end settings
}; # end mako
2025-12-02 19:21:57 +01:00
gnome-keyring = {
enable = true;
components = [
"ssh"
"pkcs11"
"secrets"
];
};
} // hostnameServices; # end services
2025-08-24 16:05:54 +02:00
programs = {
rofi = {
enable = true;
2026-01-19 18:22:45 +01:00
package = pkgs.rofi-unwrapped;
terminal = term;
2025-08-24 16:05:54 +02:00
}; # end rofi
waybar = {
enable = true;
2026-01-19 18:22:45 +01:00
systemd = {
enable = true;
target = "graphical-session.target";
};
2025-08-24 16:05:54 +02:00
settings = {
mainBar = {
layer = "bottom";
position = "top";
2026-01-19 18:22:45 +01:00
height = 28;
2025-08-24 16:05:54 +02:00
spacing = 0;
modules-left = [
"sway/workspaces"
];
modules-center = [
2025-12-02 19:21:57 +01:00
"sway/window"
2025-08-24 16:05:54 +02:00
];
modules-right = [
2025-12-02 19:21:57 +01:00
"tray"
2025-12-20 13:50:35 +01:00
"idle_inhibitor"
2025-08-24 16:05:54 +02:00
"network"
"bluetooth"
2025-08-24 16:05:54 +02:00
"pulseaudio"
"battery"
2026-01-19 18:22:45 +01:00
"sway/language"
2025-12-02 19:21:57 +01:00
"clock"
2025-08-24 16:05:54 +02:00
];
"sway/workspaces" = {
on-click = "activate";
sort-by-number = true;
format = "{value}";
};
"sway/window" = {
max-length = 64;
};
"tray" = {
2025-12-11 20:23:32 +01:00
icon-size = 24;
2025-08-24 16:05:54 +02:00
spacing = 8;
};
2025-12-20 13:50:35 +01:00
"idle_inhibitor" = {
2026-01-19 18:22:45 +01:00
format = "| {icon}";
start-activated = true;
2025-12-20 13:50:35 +01:00
format-icons = {
2026-01-19 18:22:45 +01:00
activated = "🫨";
deactivated = "😴";
2025-12-20 13:50:35 +01:00
};
};
2026-01-19 18:22:45 +01:00
"sway/language" = {
format = "| {flag}";
tooltip-format = "{long}";
2026-01-19 18:22:45 +01:00
};
2025-08-24 16:05:54 +02:00
"clock" = {
interval = 60;
2025-12-02 19:21:57 +01:00
tooltip = true;
format = "| {:%H:%M}";
tooltip-format = "{:%Y-%m-%d}";
2025-08-24 16:05:54 +02:00
};
"battery" = {
2026-01-19 18:22:45 +01:00
interval = 60;
format = "| {icon}{capacity}%";
format-charging = "| {icon}{capacity}%";
format-plugged = "| {icon}🔌{capacity}%";
2025-08-24 16:05:54 +02:00
states = {
critical = 10;
warning = 20;
2026-01-19 18:22:45 +01:00
good = 100;
2025-08-24 16:05:54 +02:00
full = 100;
over = 101;
};
2026-01-19 18:22:45 +01:00
format-icons = [ "🪫" "🪫" "🔋" "🔋" "🔋"];
2025-08-24 16:05:54 +02:00
};
"network" = {
tooltip-format = "{ifname} = {ipaddr}/{cidr}";
2026-01-19 18:22:45 +01:00
format-wifi = "| ";
format-ethernet = "| ";
format-linked = "| 🔗";
format-disconnected = "| 💥";
interval = 15;
on-click = "${uwsm} ${term} -e nmtui";
};
"bluetooth" = {
format-connected = "| ";
format-disconnected = "| ";
interval = 15;
on-click = "${uwsm} ${term} -e bluetui";
2025-08-24 16:05:54 +02:00
};
"pulseaudio" = {
2026-01-19 18:22:45 +01:00
format = "| 🔊{volume}%";
format-muted = "| 🔈0%";
format-bluetooth = "| 🎧{volume}%";
on-click = "${uwsm} pavucontrol";
2025-08-24 16:05:54 +02:00
};
}; # end mainbar
}; # end settings
2026-01-19 18:22:45 +01:00
style = ''
button {
box-shadow: inset 0 -8px transparent;
border: none;
border-radius: 0;
}
''; # end style
2025-08-24 16:05:54 +02:00
}; # end waybar
swaylock = {
enable = true;
settings = {
ignore-empty-password = true;
indicator-caps-lock = true;
}; # end settings
}; # end swaylock
2025-12-02 21:38:59 +01:00
kitty = {
2025-12-01 22:40:14 +01:00
enable = true;
settings = {
2025-12-02 21:38:59 +01:00
confirm_os_window_close = 0;
enable_audio_bell = false;
window_padding_width = 2;
2025-12-01 22:40:14 +01:00
};
2025-12-02 21:38:59 +01:00
}; # end kitty
2025-08-24 16:05:54 +02:00
}; # end programs
2025-12-11 20:23:32 +01:00
gtk = {
2025-12-01 22:40:14 +01:00
enable = true;
2025-12-11 20:23:32 +01:00
gtk2.enable = true;
gtk3.enable = true;
gtk4.enable = true;
2025-12-01 22:40:14 +01:00
};
2026-01-08 18:05:08 +01:00
xdg = {
configFile."libinput-gestures.conf".text = ''
gesture pinch in 3 sh -c "echo key ctrl+w | ${pkgs.dotool}/bin/dotool"
gesture swipe left 3 ${swaymsg} workspace prev
gesture swipe right 3 ${swaymsg} workspace next
gesture swipe down 3 ${swaymsg} move container to scratchpad
gesture swipe up 3 ${swaymsg} fullscreen
gesture swipe down 4 ${lock}
gesture pinch out 3 ${swaymsg} floating toggle
gesture pinch in 4 ${swaymsg} kill
'';
configFile."electron-flags.conf".text = ''
--enable-features=WaylandWindowDecorations,AllowQt
--ozone-platform=wayland
--gtk-version=4
'';
mimeApps = {
enable = true;
defaultApplicationPackages = [
pkgs.gnome-text-editor
pkgs.evince
pkgs.vlc
pkgs.loupe
pkgs.nautilus
pkgs.chromium
];
defaultApplications = { # mostly redundant but the additional granularity is good for reducing friction
# Text
"text/*" = [ "${pkgs.gnome-text-editor}/share/applications/org.gnome.TextEditor.desktop" ];
"application/xml" = [ "${pkgs.gnome-text-editor}/share/applications/org.gnome.TextEditor.desktop" ];
"application/json" = [ "${pkgs.gnome-text-editor}/share/applications/org.gnome.TextEditor.desktop" ];
"application/pdf" = [ "${pkgs.evince}/share/applications/org.gnome.Evince.desktop" ];
# Media
"video/*" = [ "${pkgs.vlc}/share/applications/vlc.desktop" ];
"audio/*" = [ "${pkgs.vlc}/share/applications/vlc.desktop" ];
2025-12-11 20:23:32 +01:00
2026-01-08 18:05:08 +01:00
# Browser
"text/html" = [ "${pkgs.chromium}/share/applications/chromium.desktop" ];
"application/xhtml+xml" = [ "${pkgs.chromium}/share/applications/chromium.desktop" ];
"application/x-web-app-manifest+json" = [ "${pkgs.chromium}/share/applications/chromium.desktop" ];
"application/xml-dtd" = [ "${pkgs.chromium}/share/applications/chromium.desktop" ];
2025-12-11 20:23:32 +01:00
2026-01-08 18:05:08 +01:00
# Images
"image/*" = [ "${pkgs.loupe}/share/applications/org.gnome.Loupe.desktop.desktop" ];
};
2025-12-11 20:23:32 +01:00
};
};
2025-12-04 15:40:58 +01:00
systemd.user.sessionVariables = {
2026-01-08 18:05:08 +01:00
# this right here offends me https://source.chromium.org/chromium/chromium/src/+/main:base/nix/xdg_util.cc;l=179-180
# setting GNOME_DESKTOP_SESSION_ID will fool some legacy systems into thinking we're running gnome
# this is an issue for xdg-open which can be circumvented by adding glib to the system which lets xdg-open fallback to gio-open
2025-12-04 15:40:58 +01:00
GNOME_DESKTOP_SESSION_ID = "999";
2026-01-08 19:50:06 +01:00
SHELL_THICCNESS = "LOW"; # instructs xonsh to default to a slim environment
2025-12-04 15:40:58 +01:00
};
2025-08-24 16:05:54 +02:00
} # end file