From 1d7069be6153a56825472639e63041e141efcb3f Mon Sep 17 00:00:00 2001 From: arunoruto Date: Mon, 16 Sep 2024 14:06:40 +0200 Subject: [PATCH] Manage sway as a module --- modules/home-manager/pc/desktop/default.nix | 1 + .../home-manager/pc/desktop/sway/default.nix | 147 +++++++++------- .../pc/desktop/sway/keybindings.nix | 161 +++++++++--------- .../home-manager/pc/desktop/sway/services.nix | 38 +++-- .../home-manager/pc/desktop/sway/swaylock.nix | 17 +- .../home-manager/pc/desktop/sway/swaync.nix | 24 ++- 6 files changed, 219 insertions(+), 169 deletions(-) diff --git a/modules/home-manager/pc/desktop/default.nix b/modules/home-manager/pc/desktop/default.nix index 6650158..2a75968 100644 --- a/modules/home-manager/pc/desktop/default.nix +++ b/modules/home-manager/pc/desktop/default.nix @@ -19,6 +19,7 @@ config = lib.mkIf config.desktop.enable { gnome.enable = lib.mkDefault true; hyprland.enable = lib.mkDefault true; + sway.enable = lib.mkDefault false; home.packages = with pkgs; [ gimp diff --git a/modules/home-manager/pc/desktop/sway/default.nix b/modules/home-manager/pc/desktop/sway/default.nix index bafbd25..edf1cfb 100644 --- a/modules/home-manager/pc/desktop/sway/default.nix +++ b/modules/home-manager/pc/desktop/sway/default.nix @@ -1,81 +1,98 @@ -{pkgs, ...}: let +{ + pkgs, + lib, + config, + ... +}: let image = "~/Pictures/wallpapers/anime/cafe-at-night.png"; lockscreen = "${pkgs.swaylock}/bin/swaylock --image ${image}"; in { imports = [ ./services.nix - ./theme.nix + # ./theme.nix ./keybindings.nix # ./swaync.nix ./swaylock.nix ]; - wayland.windowManager.sway = { - enable = true; - # https://www.reddit.com/r/NixOS/comments/1c9n1qk/nixosrebuild_of_sway_failing_with_unable_to/ - checkConfig = false; - config = rec { - modifier = "Mod4"; - terminal = "wezterm"; - fonts = { - names = ["FiraCode Nerd Font Mono"]; - style = "Regular"; - size = 10.0; - }; - window = { - border = 2; - titlebar = false; - }; - gaps = { - inner = 8; - outer = -5; - smartBorders = "on"; - smartGaps = true; - }; - input = { - "type:keyboard" = { - xkb_layout = "de"; - xkb_variant = "nodeadkeys"; + + options.sway.enable = lib.mkEnableOption "Custom sway config"; + + config = lib.mkIf config.sway.enable { + sway = { + keybindings.enable = lib.mkDefault true; + services.enable = lib.mkDefault true; + lock.enable = lib.mkDefault true; + # notify.enable = lib.mkDefault true; + }; + + wayland.windowManager.sway = { + enable = true; + # https://www.reddit.com/r/NixOS/comments/1c9n1qk/nixosrebuild_of_sway_failing_with_unable_to/ + checkConfig = false; + config = rec { + modifier = "Mod4"; + terminal = "wezterm"; + fonts = { + names = ["FiraCode Nerd Font Mono"]; + style = "Regular"; + size = 10.0; }; - "type:touchpad" = { - click_method = "clickfinger"; - left_handed = "disabled"; - tap = "enabled"; - natural_scroll = "enabled"; - dwt = "enabled"; - accel_profile = "flat"; - pointer_accel = "0.25"; + window = { + border = 2; + titlebar = false; }; - }; - output = { - "*" = { - # bg = "${image} fill"; - scale = "1.25"; + gaps = { + inner = 8; + outer = -5; + smartBorders = "on"; + smartGaps = true; }; - }; - keybindings = { - "${modifier}+Shift+l" = "exec ${lockscreen}"; - }; - bars = [ - { - position = "top"; - mode = "dock"; - hiddenState = "hide"; - command = "${pkgs.waybar}/bin/waybar"; - #command = "${pkgs.sway}/bin/swaybar"; - #statusCommand = "${pkgs.i3status}/bin/i3status"; - workspaceButtons = true; - workspaceNumbers = false; - trayOutput = "primary"; - fonts = { - names = ["FiraCode Nerd Font Mono"]; - style = "Regular"; - size = 11.0; + input = { + "type:keyboard" = { + xkb_layout = "de"; + xkb_variant = "nodeadkeys"; }; - } - ]; + "type:touchpad" = { + click_method = "clickfinger"; + left_handed = "disabled"; + tap = "enabled"; + natural_scroll = "enabled"; + dwt = "enabled"; + accel_profile = "flat"; + pointer_accel = "0.25"; + }; + }; + output = { + "*" = { + # bg = "${image} fill"; + scale = "1.25"; + }; + }; + keybindings = { + "${modifier}+Shift+l" = "exec ${lockscreen}"; + }; + bars = [ + { + position = "top"; + mode = "dock"; + hiddenState = "hide"; + command = "${pkgs.waybar}/bin/waybar"; + #command = "${pkgs.sway}/bin/swaybar"; + #statusCommand = "${pkgs.i3status}/bin/i3status"; + workspaceButtons = true; + workspaceNumbers = false; + trayOutput = "primary"; + fonts = { + names = ["FiraCode Nerd Font Mono"]; + style = "Regular"; + size = 11.0; + }; + } + ]; + }; + extraConfig = '' + #blur enable + ''; }; - extraConfig = '' - #blur enable - ''; }; } diff --git a/modules/home-manager/pc/desktop/sway/keybindings.nix b/modules/home-manager/pc/desktop/sway/keybindings.nix index 68832cd..27ff9df 100644 --- a/modules/home-manager/pc/desktop/sway/keybindings.nix +++ b/modules/home-manager/pc/desktop/sway/keybindings.nix @@ -1,6 +1,7 @@ { config, pkgs, + lib, ... }: let modifier = config.wayland.windowManager.sway.config.modifier; @@ -34,84 +35,88 @@ ws9 = "number 9"; ws0 = "number 10"; in { - wayland.windowManager.sway = { - config = rec { - defaultWorkspace = "workspace ${ws1}"; - keybindings = { - "${modifier}+Return" = "exec ${terminal}"; - "${modifier}+Shift+q" = "kill"; - "${modifier}+d" = "exec ${menu}"; - #"${modifier}+Shift+l" = "exec ${lockscreen}"; - - "${modifier}+${left}" = "focus left"; - "${modifier}+${down}" = "focus down"; - "${modifier}+${up}" = "focus up"; - "${modifier}+${right}" = "focus right"; - - "${modifier}+Shift+${left}" = "move left"; - "${modifier}+Shift+${down}" = "move down"; - "${modifier}+Shift+${up}" = "move up"; - "${modifier}+Shift+${right}" = "move right"; - - "${modifier}+b" = "splith"; - "${modifier}+v" = "splitv"; - "${modifier}+f" = "fullscreen toggle"; - "${modifier}+a" = "focus parent"; - - "${modifier}+s" = "layout stacking"; - "${modifier}+w" = "layout tabbed"; - "${modifier}+e" = "layout toggle split"; - - "${modifier}+Shift+space" = "floating toggle"; - "${modifier}+space" = "focus mode_toggle"; - - "${modifier}+1" = "workspace ${ws1}"; - "${modifier}+2" = "workspace ${ws2}"; - "${modifier}+3" = "workspace ${ws3}"; - "${modifier}+4" = "workspace ${ws4}"; - "${modifier}+5" = "workspace ${ws5}"; - "${modifier}+6" = "workspace ${ws6}"; - "${modifier}+7" = "workspace ${ws7}"; - "${modifier}+8" = "workspace ${ws8}"; - "${modifier}+9" = "workspace ${ws9}"; - "${modifier}+0" = "workspace ${ws0}"; - - "${modifier}+Shift+1" = "move container to workspace ${ws1}"; - "${modifier}+Shift+2" = "move container to workspace ${ws2}"; - "${modifier}+Shift+3" = "move container to workspace ${ws3}"; - "${modifier}+Shift+4" = "move container to workspace ${ws4}"; - "${modifier}+Shift+5" = "move container to workspace ${ws5}"; - "${modifier}+Shift+6" = "move container to workspace ${ws6}"; - "${modifier}+Shift+7" = "move container to workspace ${ws7}"; - "${modifier}+Shift+8" = "move container to workspace ${ws8}"; - "${modifier}+Shift+9" = "move container to workspace ${ws9}"; - "${modifier}+Shift+0" = "move container to workspace ${ws0}"; - - "${modifier}+Shift+minus" = "move scratchpad"; - "${modifier}+minus" = "scratchpad show"; - - "${modifier}+Shift+r" = "reload"; - "${modifier}+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'"; - - "${modifier}+r" = "mode resize"; - - # Brightness - "XF86MonBrightnessDown" = "exec light -U 5"; - "XF86MonBrightnessUp" = "exec light -A 5"; - - # Volume - "XF86AudioRaiseVolume" = "exec 'wpctl set-volume @DEFAULT_SINK@ 5%+ -l 1.0'"; - "XF86AudioLowerVolume" = "exec 'wpctl set-volume @DEFAULT_SINK@ 5%-'"; - "XF86AudioMute" = "exec 'wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle'"; - - # Media control - "XF86AudioPlay" = "exec playerctl play-pause"; - "XF86AudioPause" = "exec playerctl play-pause"; - "XF86AudioNext" = "exec playerctl next"; - "XF86AudioPrev" = "exec playerctl previous"; - - # Screenshots - "Print" = ''exec grim -g "$(slurp -d)" - | wl-copy''; + options.sway.keybindings.enable = lib.mkEnableOption "Custom sway keybindings"; + + config = lib.mkIf config.sway.keybindings.enable { + wayland.windowManager.sway = { + config = rec { + defaultWorkspace = "workspace ${ws1}"; + keybindings = { + "${modifier}+Return" = "exec ${terminal}"; + "${modifier}+Shift+q" = "kill"; + "${modifier}+d" = "exec ${menu}"; + #"${modifier}+Shift+l" = "exec ${lockscreen}"; + + "${modifier}+${left}" = "focus left"; + "${modifier}+${down}" = "focus down"; + "${modifier}+${up}" = "focus up"; + "${modifier}+${right}" = "focus right"; + + "${modifier}+Shift+${left}" = "move left"; + "${modifier}+Shift+${down}" = "move down"; + "${modifier}+Shift+${up}" = "move up"; + "${modifier}+Shift+${right}" = "move right"; + + "${modifier}+b" = "splith"; + "${modifier}+v" = "splitv"; + "${modifier}+f" = "fullscreen toggle"; + "${modifier}+a" = "focus parent"; + + "${modifier}+s" = "layout stacking"; + "${modifier}+w" = "layout tabbed"; + "${modifier}+e" = "layout toggle split"; + + "${modifier}+Shift+space" = "floating toggle"; + "${modifier}+space" = "focus mode_toggle"; + + "${modifier}+1" = "workspace ${ws1}"; + "${modifier}+2" = "workspace ${ws2}"; + "${modifier}+3" = "workspace ${ws3}"; + "${modifier}+4" = "workspace ${ws4}"; + "${modifier}+5" = "workspace ${ws5}"; + "${modifier}+6" = "workspace ${ws6}"; + "${modifier}+7" = "workspace ${ws7}"; + "${modifier}+8" = "workspace ${ws8}"; + "${modifier}+9" = "workspace ${ws9}"; + "${modifier}+0" = "workspace ${ws0}"; + + "${modifier}+Shift+1" = "move container to workspace ${ws1}"; + "${modifier}+Shift+2" = "move container to workspace ${ws2}"; + "${modifier}+Shift+3" = "move container to workspace ${ws3}"; + "${modifier}+Shift+4" = "move container to workspace ${ws4}"; + "${modifier}+Shift+5" = "move container to workspace ${ws5}"; + "${modifier}+Shift+6" = "move container to workspace ${ws6}"; + "${modifier}+Shift+7" = "move container to workspace ${ws7}"; + "${modifier}+Shift+8" = "move container to workspace ${ws8}"; + "${modifier}+Shift+9" = "move container to workspace ${ws9}"; + "${modifier}+Shift+0" = "move container to workspace ${ws0}"; + + "${modifier}+Shift+minus" = "move scratchpad"; + "${modifier}+minus" = "scratchpad show"; + + "${modifier}+Shift+r" = "reload"; + "${modifier}+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'"; + + "${modifier}+r" = "mode resize"; + + # Brightness + "XF86MonBrightnessDown" = "exec light -U 5"; + "XF86MonBrightnessUp" = "exec light -A 5"; + + # Volume + "XF86AudioRaiseVolume" = "exec 'wpctl set-volume @DEFAULT_SINK@ 5%+ -l 1.0'"; + "XF86AudioLowerVolume" = "exec 'wpctl set-volume @DEFAULT_SINK@ 5%-'"; + "XF86AudioMute" = "exec 'wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle'"; + + # Media control + "XF86AudioPlay" = "exec playerctl play-pause"; + "XF86AudioPause" = "exec playerctl play-pause"; + "XF86AudioNext" = "exec playerctl next"; + "XF86AudioPrev" = "exec playerctl previous"; + + # Screenshots + "Print" = ''exec grim -g "$(slurp -d)" - | wl-copy''; + }; }; }; }; diff --git a/modules/home-manager/pc/desktop/sway/services.nix b/modules/home-manager/pc/desktop/sway/services.nix index 2120854..bdf29ba 100644 --- a/modules/home-manager/pc/desktop/sway/services.nix +++ b/modules/home-manager/pc/desktop/sway/services.nix @@ -1,4 +1,10 @@ -# {pkgs, ...}: let +{ + pkgs, + lib, + config, + ... +}: +# let # flavor = "macchiato"; # catppuccin-rofi = builtins.fetchGit { # url = "https://github.com/catppuccin/rofi"; @@ -10,19 +16,23 @@ # }; # in { - programs.rofi = { - enable = true; - # font = "FiraCode Nerd Font Mono 14"; - # theme = "${catppuccin-rofi}/basic/.local/share/rofi/themes/catppuccin-${flavor}.rasi"; - }; + options.sway.services.enable = lib.mkEnableOption "Custom sway services"; - # services.mako = { - # enable = true; - # defaultTimeout = 10000; - # # extraConfig = builtins.readFile "${catppuccin-mako}/src/${flavor}"; - # }; + config = lib.mkIf config.sway.services.enable { + programs.rofi = { + enable = true; + # font = "FiraCode Nerd Font Mono 14"; + # theme = "${catppuccin-rofi}/basic/.local/share/rofi/themes/catppuccin-${flavor}.rasi"; + }; - #services.wob = { - # enable = true; - #}; + # services.mako = { + # enable = true; + # defaultTimeout = 10000; + # # extraConfig = builtins.readFile "${catppuccin-mako}/src/${flavor}"; + # }; + + #services.wob = { + # enable = true; + #}; + }; } diff --git a/modules/home-manager/pc/desktop/sway/swaylock.nix b/modules/home-manager/pc/desktop/sway/swaylock.nix index 1891baf..d0a787a 100644 --- a/modules/home-manager/pc/desktop/sway/swaylock.nix +++ b/modules/home-manager/pc/desktop/sway/swaylock.nix @@ -1,12 +1,21 @@ -{pkgs, ...}: let +{ + pkgs, + lib, + config, + ... +}: let flavor = "macchiato"; catppuccin-swaylock = builtins.fetchGit { url = "https://github.com/catppuccin/swaylock"; ref = "main"; }; in { - programs.swaylock = { - enable = true; + options.sway.lock.enable = lib.mkEnableOption "Custom sway lock config"; + + config = lib.mkIf config.sway.lock.enable { + programs.swaylock = { + enable = true; + }; + # home.file.".config/swaylock/config".source = "${catppuccin-swaylock}/themes/macchiato.conf"; }; - # home.file.".config/swaylock/config".source = "${catppuccin-swaylock}/themes/macchiato.conf"; } diff --git a/modules/home-manager/pc/desktop/sway/swaync.nix b/modules/home-manager/pc/desktop/sway/swaync.nix index 7d5c651..3778a4c 100644 --- a/modules/home-manager/pc/desktop/sway/swaync.nix +++ b/modules/home-manager/pc/desktop/sway/swaync.nix @@ -1,4 +1,8 @@ -let +{ + config, + lib, + ... +}: let version = "0.2.2"; flavor = "macchiato"; catppuccin-swaync = ""; @@ -7,13 +11,17 @@ let # hash = ""; # }; in { - programs.swaync = { - enable = true; - settings = { - positionX = "right"; - positionY = "bottom"; - layer = "overlay"; + options.sway.notify.enable = lib.mkEnableOption "Custom sway notification"; + + config = lib.mkIf config.sway.notify.enable { + programs.swaync = { + enable = true; + settings = { + positionX = "right"; + positionY = "bottom"; + layer = "overlay"; + }; }; + # home.file.".config/swaync/style.css".source = "${catppuccin-swaync}"; }; - # home.file.".config/swaync/style.css".source = "${catppuccin-swaync}"; }