wm: Refactor to remove i3

This commit is contained in:
Quentin Boyer 2025-08-17 20:37:58 +02:00
parent a505acde5c
commit bc474242de
6 changed files with 243 additions and 650 deletions

View file

@ -37,6 +37,8 @@
};
};
traxys.wm = "sway";
traxys.waybar.modules.battery.enable = true;
traxys.waybar.modules."network#wifi" = {
enable = true;

268
wm/hm.nix
View file

@ -5,236 +5,62 @@
...
}:
{
xdg.portal = {
enable = true;
config = {
sway = {
default = "gtk";
"org.freedesktop.impl.portal.Screenshot" = "wlr";
"org.freedesktop.impl.portal.ScreenCast" = "wlr";
};
};
imports = [ ./sway.nix ];
extraPortals = with pkgs; [
xdg-desktop-portal-wlr
xdg-desktop-portal-gtk
];
};
imports = [ ./i3like.nix ];
gtk = {
enable = true;
font = {
name = "DejaVu Sans";
};
theme.name = "Adwaita";
gtk3.extraConfig = {
gtk-application-prefer-dark-theme = 1;
};
gtk4.extraConfig = {
gtk-application-prefer-dark-theme = 1;
options = {
traxys.wm = lib.mkOption {
type = lib.types.enum [ "sway" ];
};
};
home.packages = with pkgs; [ kdePackages.breeze ];
config = {
qt = {
enable = true;
platformTheme.name = "qtct";
};
dconf.settings = {
"org/gnome/desktop/interface" = {
color-scheme = "prefer-dark";
};
};
home.pointerCursor = {
gtk.enable = true;
x11.enable = true;
size = 24;
package = pkgs.adwaita-icon-theme;
name = "Adwaita";
};
programs.foot.settings.colors."16" = "ff9e64";
programs.foot.settings.colors."17" = "db4b4b";
home.sessionVariables = {
EXA_COLORS = "xx=38;5;8";
};
programs.rofi = {
enable = true;
theme = "solarized_alternate";
terminal = "${config.terminal.command}";
};
wm =
let
mod = config.wm.modifier;
in
{
gtk = {
enable = true;
kind = "sway";
modifier = "Mod4";
font = {
name = "Hack Nerd Font";
style = "Regular";
size = 14.0;
name = "DejaVu Sans";
};
bar = {
font = {
name = "Hack Nerd Font Mono";
style = "Regular";
size = 11.0;
};
theme.name = "Adwaita";
gtk3.extraConfig = {
gtk-application-prefer-dark-theme = 1;
};
wallpaper = "${pkgs.nixos-artwork.wallpapers.simple-dark-gray}/share/backgrounds/nixos/nix-wallpaper-simple-dark-gray.png";
printScreen = {
enable = true;
keybind = "Print";
};
menu = {
enable = true;
keybind = "${mod}+e";
};
exit = {
enable = true;
keybind = "${mod}+Shift+e";
};
notifications = {
enable = true;
font = "hack nerd font 10";
defaultTimeout = 7000;
};
startup = [
{
command = lib.getExe (
pkgs.sway-assign-cgroups.override {
python3Packages = pkgs.python3Packages // {
dbus-next = pkgs.python3Packages.dbus-next.overridePythonAttrs (_: {
doCheck = false;
});
};
}
);
}
{ command = "signal-desktop"; }
{ command = "discord"; }
{ command = "firefox"; }
{ command = "element-desktop"; }
{ command = "thunderbird"; }
{ command = "systemctl --user import-environment DISPLAY WAYLAND_DISPLAY SWAYSOCK"; }
{
command = "hash dbus-update-activation-environment 2>/dev/null && dbus-update-activation-environment --systemd DISPLAY WAYLAND_DISPLAY SWAYSOCK";
}
{
command = "${pkgs.plasma5Packages.kdeconnect-kde}/libexec/kdeconnectd";
always = true;
}
];
workspaces = {
moveModifier = "Shift";
definitions = {
"1:" = {
key = "1";
};
"2:" = {
key = "2";
};
"3:" = {
key = "3";
};
"4" = {
key = "4";
};
"5" = {
key = "5";
};
"6" = {
key = "6";
};
"7" = {
key = "7";
};
"" = {
key = "8";
assign = [ "Spotify" ];
};
"" = {
key = "g";
assign = [
"Element"
"Signal"
"Discord"
];
};
"" = {
key = "h";
assign = [ "Thunderbird" ];
};
};
};
keybindings = {
"${mod}+Shift+l" = "exec ${pkgs.swaylock-fancy}/bin/swaylock-fancy";
# Media Keys
"XF86AudioRaiseVolume" = "exec ${pkgs.pulseaudio}/bin/pactl set-sink-volume @DEFAULT_SINK@ '+10%'";
"XF86AudioLowerVolume" = "exec ${pkgs.pulseaudio}/bin/pactl set-sink-volume @DEFAULT_SINK@ '-10%'";
"XF86AudioMute" = "exec ${pkgs.pulseaudio}/bin/pactl set-sink-mute @DEFAULT_SINK@ toggle";
"XF86AudioPlay" = "exec ${pkgs.playerctl}/bin/playerctl -p spotify play-pause";
"XF86AudioNext" = "exec ${pkgs.playerctl}/bin/playerctl -p spotify next";
"XF86AudioPrev" = "exec ${pkgs.playerctl}/bin/playerctl -p spotify previous";
"XF86MonBrightnessDown" = "exec ${lib.getExe pkgs.brightnessctl} set 10%-";
"XF86MonBrightnessUp" = "exec ${lib.getExe pkgs.brightnessctl} set 10%+";
"XF86Display" = "exec ${lib.getExe' pkgs.wl-mirror "wl-present"} mirror";
"${mod}+space" = "exec foot nvim +WikiIndex";
"${mod}+Shift+space" = "exec foot nvim +WikiPages";
# Gromit
"Ctrl+Shift+I" = "exec ${pkgs.gromit-mpx}/bin/gromit-mpx -a";
"Ctrl+Shift+D" = "exec ${pkgs.gromit-mpx}/bin/gromit-mpx -q";
"Ctrl+Shift+H" = "exec ${pkgs.gromit-mpx}/bin/gromit-mpx -c";
# Change keyboard layout
"${mod}+dollar" = "input type:keyboard xkb_switch_layout next"; # Dvorak
"${mod}+grave" = "input type:keyboard xkb_switch_layout next"; # Qwerty
# Focus
"${mod}+Left" = "focus left";
"${mod}+Right" = "focus right";
"${mod}+Down" = "focus down";
"${mod}+Up" = "focus up";
"${mod}+Shift+Left" = "move left";
"${mod}+Shift+Right" = "move right";
"${mod}+Shift+Down" = "move down";
"${mod}+Shift+Up" = "move up";
# Layout
"${mod}+n" = "fullscreen toggle";
"${mod}+o" = "layout tabbed";
# Misc
"${mod}+Shift+Q" = "kill";
"${mod}+Shift+J" = "reload";
"${mod}+Return" = "exec ${config.terminal.command}";
"${mod}+p" = "mode resize";
"${mod}+Shift+P" = "restart";
"${mod}+Shift+S" = "exec ${config.programs.rofi.package}/bin/rofi -show ssh";
gtk4.extraConfig = {
gtk-application-prefer-dark-theme = 1;
};
};
home.packages = with pkgs; [ kdePackages.breeze ];
qt = {
enable = true;
platformTheme.name = "qtct";
};
dconf.settings = {
"org/gnome/desktop/interface" = {
color-scheme = "prefer-dark";
};
};
home.pointerCursor = {
gtk.enable = true;
x11.enable = true;
size = 24;
package = pkgs.adwaita-icon-theme;
name = "Adwaita";
};
programs.foot.settings.colors."16" = "ff9e64";
programs.foot.settings.colors."17" = "db4b4b";
home.sessionVariables = {
EXA_COLORS = "xx=38;5;8";
};
programs.rofi = {
enable = true;
theme = "solarized_alternate";
terminal = "${config.terminal.command}";
};
};
}

118
wm/i3.nix
View file

@ -1,118 +0,0 @@
{
config,
lib,
pkgs,
...
}:
with builtins;
with lib;
let
cfg = config.wm;
common = import ./i3like-utils.nix { inherit config; };
startupNotifications =
if cfg.notifications.enable then
[
{
command = "${config.services.dunst.package}/bin/dunst";
notification = false;
always = true;
}
]
else
[ ];
wallpaperSet =
if cfg.wallpaper != null then
[
{
command = "${pkgs.feh}/bin/feh --bg-scale ${cfg.wallpaper}";
always = true;
notification = false;
}
]
else
[ ];
startup = startupNotifications ++ wallpaperSet ++ cfg.startup;
in
{
config = mkIf (cfg.enable && cfg.kind == "i3") {
programs = {
i3status-rust = {
enable = true;
bars.bottom = {
blocks = [
{
block = "disk_space";
path = "/";
info_type = "used";
unit = "GB";
alert = 90;
warning = 80;
format = ":{used}/{total}";
}
{
block = "disk_space";
path = "/home";
info_type = "used";
unit = "GB";
alert = 90;
warning = 80;
format = ":{used}/{total}";
}
{
block = "load";
format = ":{1m}";
}
{
block = "sound";
driver = "pulseaudio";
}
{
block = "music";
player = "spotify";
format = "{combo}";
}
{ block = "time"; }
];
};
};
};
services.dunst = mkIf cfg.notifications.enable {
enable = true;
settings = {
global = {
timeout = "${toString cfg.notifications.defaultTimeout}ms";
inherit (cfg.notifications) font;
};
};
};
wm.printScreen.command = mkDefault "${pkgs.maim}/bin/maim -s | ${pkgs.xclip}/bin/xclip -selection clipboard -t image/png";
wm.exit.command = mkDefault "\"i3-nagbar -t warning -m 'You pressed the exit shortcut. Do you really want to exit i3? This will end your X session.' -B 'Yes, exit i3' 'i3-msg exit'\"";
xsession = {
enable = true;
windowManager.i3 = {
enable = true;
config = {
inherit startup;
inherit (common) keybindings;
inherit (common) workspaceOutputAssign;
inherit (common) assigns;
fonts = common.mkFont cfg.font;
inherit (cfg) modifier;
bars = [
{
fonts = common.mkFont cfg.bar.font;
statusCommand = "${config.programs.i3status-rust.package}/bin/i3status-rs ${config.home.homeDirectory}/.config/i3status-rust/config-bottom.toml";
}
];
};
};
scriptPath = ".hm-xsession";
};
};
}

View file

@ -1,53 +0,0 @@
{ config }:
with builtins;
let
cfg = config.wm;
addKeyIf =
cond: keybinds: newkey:
if cond then newkey // keybinds else keybinds;
keybindSolo =
keys: submod: addKeyIf submod.enable keys { "${submod.keybind}" = "exec ${submod.command}"; };
keydefs = [
cfg.printScreen
cfg.menu
cfg.exit
];
keybindingsKeydef = foldl' keybindSolo cfg.keybindings keydefs;
mod = cfg.modifier;
ws_def = cfg.workspaces.definitions;
get_ws = ws: getAttr ws ws_def;
workspaceFmt =
name:
let
inherit ((get_ws name)) key;
in
{
"${mod}+${key}" = "workspace ${name}";
"${mod}+${cfg.workspaces.moveModifier}+${key}" = "move container to workspace ${name}";
};
workspaceAssign = name: {
workspace = name;
inherit ((get_ws name)) output;
};
classAssign = name: { "${name}" = map (app: { class = "${app}"; }) (get_ws name).assign; };
in
{
mkFont = mod: {
names = [ mod.name ];
inherit (mod) style;
inherit (mod) size;
};
keybindings =
(foldl' (x: y: x // y) { } (map workspaceFmt (attrNames ws_def))) // keybindingsKeydef;
workspaceOutputAssign = map workspaceAssign (
filter (ws: (get_ws ws).output != null) (attrNames ws_def)
);
assigns = foldl' (x: y: x // y) { } (map classAssign (attrNames ws_def));
}

View file

@ -1,193 +0,0 @@
{
config,
lib,
pkgs,
...
}:
with builtins;
with lib;
{
imports = [
./i3.nix
./sway.nix
];
options = {
wm = {
enable = mkOption {
type = types.bool;
default = false;
description = "Manage window Manager";
};
kind = mkOption {
type = types.enum [
"i3"
"sway"
];
default = "sway";
description = "WM to use";
};
modifier = mkOption {
type = types.str;
description = "modifier key to use";
};
font = {
name = mkOption {
type = types.str;
description = "Font to use";
};
style = mkOption {
type = types.str;
description = "Font style";
};
size = mkOption {
type = types.float;
description = "Font size";
};
};
bar = {
font = {
name = mkOption {
type = types.str;
description = "Font to use for the bar";
};
style = mkOption {
type = types.str;
description = "Font style for the bar";
};
size = mkOption {
type = types.float;
description = "Font size for the bar";
};
};
};
printScreen = {
enable = mkOption {
type = types.bool;
description = "Enable PrintScreen functionality";
default = false;
};
keybind = mkOption {
type = types.str;
description = "PrintScreen key";
};
command = mkOption {
type = types.str;
description = "Print screen command";
};
};
menu = {
enable = mkOption {
type = types.bool;
default = false;
description = "Enable menu";
};
keybind = mkOption {
type = types.str;
description = "Menu keybind";
};
command = mkOption {
type = types.str;
description = "Command to launch the menu";
default = "${config.programs.rofi.package}/bin/rofi -show drun -show-icons";
};
};
exit = {
enable = mkOption {
type = types.bool;
default = false;
description = "Enable exit keybind";
};
keybind = mkOption {
type = types.str;
description = "Menu keybind";
};
command = mkOption {
type = types.str;
description = "Command to exit the WM";
};
};
notifications = {
enable = mkOption {
type = types.bool;
default = false;
description = "Enable notifications";
};
font = mkOption {
type = types.str;
description = "Font + Size";
};
defaultTimeout = mkOption {
type = types.int;
description = "Default timeout for notifications (in ms)";
};
};
startup = mkOption {
type = types.listOf (
types.submodule {
options = {
command = mkOption {
type = types.str;
description = "Command that will be executed on startup.";
};
always = mkOption {
type = types.bool;
default = false;
description = "Whether to run command on each ${moduleName} restart.";
};
};
}
);
};
wallpaper = mkOption {
type = types.nullOr types.path;
description = "wallpaper";
};
workspaces = {
definitions = mkOption {
type = types.attrsOf (
types.submodule {
options = {
key = mkOption {
type = types.str;
description = "Keybind for the workspace";
};
output = mkOption {
type = types.nullOr types.str;
description = "Assign workspace to output";
default = null;
};
assign = mkOption {
type = types.listOf types.str;
description = "Assign class elements";
default = [ ];
};
};
}
);
description = "Workspace descriptions";
default = { };
};
moveModifier = mkOption {
type = types.str;
description = "Modifier key to move windows to workspaces";
};
};
keybindings = mkOption {
type = types.attrsOf (types.nullOr types.str);
description = "keybindings";
};
};
};
}

View file

@ -4,72 +4,104 @@
pkgs,
...
}:
with lib;
with builtins;
let
cfg = config.wm;
common = import ./i3like-utils.nix { inherit config; };
startupNotifications =
if cfg.notifications.enable then
[
{
command = "${pkgs.mako}/bin/mako";
always = true;
}
]
else
[ ];
startup = startupNotifications ++ cfg.startup;
in
{
config = mkIf (cfg.enable && cfg.kind == "sway") {
home.packages = with pkgs; [ sway ] ++ (if cfg.wallpaper != null then [ pkgs.swaybg ] else [ ]);
home.sessionVariables = {
MOZ_ENABLE_WAYLAND = "1";
XDG_CURRENT_DESKTOP = "sway";
LIBSEAT_BACKEND = "logind";
_JAVA_AWT_WM_NONREPARENTING = 1;
};
programs.rofi.package = pkgs.rofi-wayland;
services.mako = mkIf cfg.notifications.enable {
enable = true;
settings = {
inherit (cfg.notifications) font;
margin = "20,20,5,5";
default-timeout = cfg.notifications.defaultTimeout;
"mode=do-not-disturb" = {
invisible = 1;
};
lib.mkIf (config.traxys.wm == "sway") {
xdg.portal = {
enable = true;
config = {
sway = {
default = "gtk";
"org.freedesktop.impl.portal.Screenshot" = "wlr";
"org.freedesktop.impl.portal.ScreenCast" = "wlr";
};
};
traxys.waybar.enable = true;
traxys.waybar.modules."sway/workspaces".enable = true;
traxys.waybar.modules."sway/mode".enable = true;
traxys.waybar.modules."sway/window".enable = true;
extraPortals = with pkgs; [
xdg-desktop-portal-wlr
xdg-desktop-portal-gtk
];
};
wm.printScreen.command = mkDefault "${pkgs.grim}/bin/grim -g \"$(${pkgs.slurp}/bin/slurp)\" - | ${pkgs.wl-clipboard}/bin/wl-copy -t image/png";
wm.exit.command = mkDefault "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'";
home.packages = with pkgs; [
sway
swaybg
];
home.sessionVariables = {
MOZ_ENABLE_WAYLAND = "1";
XDG_CURRENT_DESKTOP = "sway";
LIBSEAT_BACKEND = "logind";
_JAVA_AWT_WM_NONREPARENTING = 1;
};
programs.rofi.package = pkgs.rofi-wayland;
services.mako = {
enable = true;
settings = {
font = "hack nerd font 10";
margin = "20,20,5,5";
default-timeout = 7000;
"mode=do-not-disturb" = {
invisible = 1;
};
};
};
traxys.waybar.enable = true;
traxys.waybar.modules."sway/workspaces".enable = true;
traxys.waybar.modules."sway/mode".enable = true;
traxys.waybar.modules."sway/window".enable = true;
wayland.windowManager.sway = {
enable = true;
extraConfig =
let
wallpaper = "${pkgs.nixos-artwork.wallpapers.simple-dark-gray}/share/backgrounds/nixos/nix-wallpaper-simple-dark-gray.png";
in
''
output "*" bg ${wallpaper} fill
for_window [app_id="discord"] border none
'';
config =
let
mod = "Mod4";
in
{
modifier = mod;
wayland.windowManager.sway = {
enable = true;
extraConfig = mkMerge [
(mkIf (cfg.wallpaper != null) ''
output "*" bg ${cfg.wallpaper} fill
'')
''
for_window [app_id="discord"] border none
''
];
config = {
inherit startup;
inherit (cfg) modifier;
bars = [ { command = "waybar"; } ];
startup = [
{
command = "${pkgs.mako}/bin/mako";
always = true;
}
{
command = lib.getExe (
pkgs.sway-assign-cgroups.override {
python3Packages = pkgs.python3Packages // {
dbus-next = pkgs.python3Packages.dbus-next.overridePythonAttrs (_: {
doCheck = false;
});
};
}
);
}
{ command = "signal-desktop"; }
{ command = "discord"; }
{ command = "firefox"; }
{ command = "element-desktop"; }
{ command = "thunderbird"; }
{ command = "systemctl --user import-environment DISPLAY WAYLAND_DISPLAY SWAYSOCK"; }
{
command = "hash dbus-update-activation-environment 2>/dev/null && dbus-update-activation-environment --systemd DISPLAY WAYLAND_DISPLAY SWAYSOCK";
}
{
command = "${pkgs.plasma5Packages.kdeconnect-kde}/libexec/kdeconnectd";
always = true;
}
];
input =
let
inherit (config.extraInfo) inputs;
@ -96,7 +128,13 @@ in
in
builtins.listToAttrs (builtins.filter (s: s != null) inputsCfg);
output = config.extraInfo.outputs;
fonts = common.mkFont cfg.font;
fonts = {
names = [ "Hack Nerd Font" ];
style = "Regular";
size = 14.0;
};
window = {
titlebar = true;
commands = [
@ -110,13 +148,104 @@ in
}
];
};
inherit (common) keybindings;
inherit (common) workspaceOutputAssign;
inherit (common) assigns;
keybindings = {
"Print" = ''
exec ${pkgs.grim}/bin/grim -g \"$(${pkgs.slurp}/bin/slurp)\" - | ${pkgs.wl-clipboard}/bin/wl-copy -t image/png
'';
"${mod}+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'
'';
"${mod}+Shift+l" = "exec ${pkgs.swaylock-fancy}/bin/swaylock-fancy";
"${mod}+e" = "exec ${config.programs.rofi.package}/bin/rofi -show drun -show-icons";
"${mod}+1" = "workspace 1:";
"${mod}+Shift+1" = "move container to workspace 1:";
"${mod}+2" = "workspace 2:";
"${mod}+Shift+2" = "move container to workspace 2:";
"${mod}+3" = "workspace 3:";
"${mod}+Shift+3" = "move container to workspace 3:";
"${mod}+4" = "workspace 4";
"${mod}+Shift+4" = "move container to workspace 4";
"${mod}+5" = "workspace 5";
"${mod}+Shift+5" = "move container to workspace 5";
"${mod}+6" = "workspace 6";
"${mod}+Shift+6" = "move container to workspace 6";
"${mod}+7" = "workspace 7";
"${mod}+Shift+7" = "move container to workspace 7";
"${mod}+8" = "workspace ";
"${mod}+Shift+8" = "move container to workspace ";
"${mod}+g" = "workspace ";
"${mod}+Shift+g" = "move container to workspace ";
"${mod}+h" = "workspace ";
"${mod}+Shift+h" = "move container to workspace ";
# Media Keys
"XF86AudioRaiseVolume" = "exec ${pkgs.pulseaudio}/bin/pactl set-sink-volume @DEFAULT_SINK@ '+10%'";
"XF86AudioLowerVolume" = "exec ${pkgs.pulseaudio}/bin/pactl set-sink-volume @DEFAULT_SINK@ '-10%'";
"XF86AudioMute" = "exec ${pkgs.pulseaudio}/bin/pactl set-sink-mute @DEFAULT_SINK@ toggle";
"XF86AudioPlay" = "exec ${pkgs.playerctl}/bin/playerctl -p spotify play-pause";
"XF86AudioNext" = "exec ${pkgs.playerctl}/bin/playerctl -p spotify next";
"XF86AudioPrev" = "exec ${pkgs.playerctl}/bin/playerctl -p spotify previous";
"XF86MonBrightnessDown" = "exec ${lib.getExe pkgs.brightnessctl} set 10%-";
"XF86MonBrightnessUp" = "exec ${lib.getExe pkgs.brightnessctl} set 10%+";
"XF86Display" = "exec ${lib.getExe' pkgs.wl-mirror "wl-present"} mirror";
"${mod}+space" = "exec foot nvim +WikiIndex";
"${mod}+Shift+space" = "exec foot nvim +WikiPages";
# Gromit
"Ctrl+Shift+I" = "exec ${pkgs.gromit-mpx}/bin/gromit-mpx -a";
"Ctrl+Shift+D" = "exec ${pkgs.gromit-mpx}/bin/gromit-mpx -q";
"Ctrl+Shift+H" = "exec ${pkgs.gromit-mpx}/bin/gromit-mpx -c";
# Change keyboard layout
"${mod}+dollar" = "input type:keyboard xkb_switch_layout next"; # Dvorak
"${mod}+grave" = "input type:keyboard xkb_switch_layout next"; # Qwerty
# Focus
"${mod}+Left" = "focus left";
"${mod}+Right" = "focus right";
"${mod}+Down" = "focus down";
"${mod}+Up" = "focus up";
"${mod}+Shift+Left" = "move left";
"${mod}+Shift+Right" = "move right";
"${mod}+Shift+Down" = "move down";
"${mod}+Shift+Up" = "move up";
# Layout
"${mod}+n" = "fullscreen toggle";
"${mod}+o" = "layout tabbed";
# Misc
"${mod}+Shift+Q" = "kill";
"${mod}+Shift+J" = "reload";
"${mod}+Return" = "exec ${config.terminal.command}";
"${mod}+p" = "mode resize";
"${mod}+Shift+P" = "restart";
"${mod}+Shift+S" = "exec ${config.programs.rofi.package}/bin/rofi -show ssh";
};
assigns = {
"" = [ { class = "Ppotify"; } ];
"" = [
{ class = "Element"; }
{ class = "Signal"; }
{ class = "Discord"; }
];
"" = [ { class = "Thunderbird"; } ];
};
seat."*" = {
xcursor_theme = "${config.home.pointerCursor.name} ${toString config.home.pointerCursor.size}";
};
};
};
};
}