From 49f0b5d590ebfc54c0a84b8809f216bfb0167672 Mon Sep 17 00:00:00 2001 From: sternenseemann <0rpkxez4ksa01gb3typccl0i@systemli.org> Date: Sun, 7 Feb 2021 16:41:40 +0100 Subject: modules/user/sternenseemann: add sway service module machines/sternenseemann/wolfgang: refactor using new sway module --- machines/sternenseemann/TODO | 6 +- machines/sternenseemann/desktop-sway.nix | 290 ++++------------------- machines/sternenseemann/wolfgang.nix | 9 +- modules/module-list.nix | 1 + modules/user/sternenseemann/services/sway.nix | 317 ++++++++++++++++++++++++++ 5 files changed, 370 insertions(+), 253 deletions(-) create mode 100644 modules/user/sternenseemann/services/sway.nix diff --git a/machines/sternenseemann/TODO b/machines/sternenseemann/TODO index 733ecde7..463d0c4a 100644 --- a/machines/sternenseemann/TODO +++ b/machines/sternenseemann/TODO @@ -1,3 +1,5 @@ -[ ] get screen capture with wayland to work -[ ] port sway configuration into a somewhat generic module +[x] get screen capture with wayland to work +[x] port sway configuration into a somewhat generic module +[ ] mako module [ ] use gpg-agent module? +[ ] documentation.man without man-db, but with mandoc diff --git a/machines/sternenseemann/desktop-sway.nix b/machines/sternenseemann/desktop-sway.nix index 57040cec..57d9d7ee 100644 --- a/machines/sternenseemann/desktop-sway.nix +++ b/machines/sternenseemann/desktop-sway.nix @@ -7,44 +7,31 @@ let getBins ; - inherit (pkgs.writers) - writeDashBin + inherit (pkgs.vuizvui.sternenseemann) + tep ; - bins = (getBins pkgs.systemd [ "systemctl" ]) - // (getBins pkgs.xurls [ "xurls" ]) - // (getBins pkgs.bemenu [ "bemenu" ]) - // (getBins pkgs.dbus [ "dbus-run-session" ]) - // (getBins pkgs.sway [ "sway" "swaymsg" ]) + bins = (getBins pkgs.xurls [ "xurls" ]) + // (getBins pkgs.bemenu [ "bemenu" "bemenu-run" ]) + // (getBins tep [ "tep" ]) + // (getBins pkgs.grim [ "grim" ]) + // (getBins pkgs.slurp [ "slurp" ]) + // (getBins pkgs.mako [ "makoctl" ]) + // (getBins screenshot [ "screenshot" ]) + // (getBins pkgs.foot [ "foot" ]) ; - # manual start script - startSway = writeDashBin "start-sway" '' - ${bins.systemctl} --user import-environment - ${bins.systemctl} --user start sway.service - ''; - - # sway scripts for systemd - swayService = writeDashBin "sway-service" '' - ${bins.dbus-run-session} -- "${pkgs.sway}/bin/sway" - ''; + screenshot = pkgs.writers.writeDashBin "screenshot" '' + if [ "$1" != "full" ]; then + additionalOpts='-g "$(${bins.slurp})"' + shift + fi - exitSway = writeDashBin "exit-sway" '' - ${bins.swaymsg} exit - ${bins.systemctl} --user unset-environment WAYLAND_DISPLAY - ${bins.systemctl} --user unset-environment DISPLAY + ${bins.grim} $additionalOpts -c -t png ''; - # reduce repition in sway config by generating workspace switches - wsConfig = lib.concatMapStringsSep "\n" (n: '' - bindsym $mod+${toString n} workspace number ${toString n} - bindsym $mod+Shift+${toString n} move container to workspace number ${toString n} - '') [1 2 3 4 5 6 7 8 9]; + defaultFont = "Bitstream Vera Sans Mono"; - # .Xresources file to fix DPI issues in Xwayland - xResources = pkgs.writeText "Xresources" '' - Xft.dpi: 96 - ''; in { @@ -53,201 +40,32 @@ in ]; config = { - programs.sway = { + vuizvui.user.sternenseemann.services.sway = { enable = true; - extraPackages = with pkgs; [ - vuizvui.sternenseemann.tep # emoji picker - bemenu # better dmenu - xwayland qt5.qtwayland - wl-clipboard # instead of xsel - grim slurp # screenshots - mako # notifications - ]; - wrapperFeatures = { - gtk = true; - base = true; + additionalBinds = { + "$mod+g" = "${bins.tep} copy -l 25 -p 'tep>' -i"; + "$mod+c" = "${bins.makoctl} dismiss -a"; + "$mod+x" = bins.screenshot; }; - }; - - environment.sessionVariables = { - # TODO(sterni) get screen capture working in firefox - XDG_SESSION_TYPE = "wayland"; - XDG_CURRENT_DESKTOP = "sway"; - MOZ_ENABLE_WAYLAND = "1"; - # SDL - SDL_VIDEODRIVER = "wayland"; - # QT - QT_QPA_PLATFORM = "wayland"; - QT_WAYLAND_DISABLE_WINDOWDECORATION = "1"; - }; - - services.dbus.packages = [ pkgs.mako ]; - - services.pipewire.enable = true; - xdg.portal = { - enable = true; - extraPortals = with pkgs; [ - xdg-desktop-portal-wlr - xdg-desktop-portal-gtk + term = bins.foot; + menu = "${bins.bemenu-run} -l 10 -i"; + lockArgs = [ + "-c" "FFC0CB" "-k" "-l" ]; - gtkUsePortal = true; - }; - - environment.etc = { - "sway/config".text = '' - # correct DPI after hotplugging - exec ${pkgs.xorg.xrdb}/bin/xrdb -load ${xResources} - - set $mod Mod4 - #set $term ${pkgs.kitty}/bin/kitty - set $term ${pkgs.foot}/bin/foot - set $menu ${pkgs.bemenu}/bin/bemenu-run -l 5 -i - set $makoctl ${pkgs.mako}/bin/makoctl - - # neo arrow keys - set $left i - set $right e - set $up l - set $down a - - bindsym $mod+Shift+c reload - - bindsym $mod+Return exec $term - bindsym $mod+d exec $menu - - bindsym $mod+c exec $makoctl dismiss -a - - bindsym $mod+g exec ${pkgs.vuizvui.sternenseemann.tep}/bin/tep copy -l 25 -p 'tep>' -i - - bindsym $mod+Shift+q kill - - bindsym $mod+h splith - bindsym $mod+v splitv - - bindsym $mod+s layout stacking - bindsym $mod+t layout tabbed - bindsym $mod+n layout toggle split - - bindsym $mod+f fullscreen - - bindsym $mod+Shift+space floating toggle - bindsym $mod+space focus mode_toggle - floating_modifier $mod normal - - bindsym $mod+$left focus left - bindsym $mod+$down focus down - bindsym $mod+$up focus up - bindsym $mod+$right focus right - - bindsym $mod+p focus parent - - bindsym $mod+Shift+$left move left - bindsym $mod+Shift+$down move down - bindsym $mod+Shift+$up move up - bindsym $mod+Shift+$right move right - - mode "resize" { - bindsym $left resize shrink width 10px - bindsym $down resize grow height 10px - bindsym $up resize shrink height 10px - bindsym $right resize grow width 10px - - bindsym Return mode "default" - bindsym Escape mode "default" - } - bindsym $mod+r mode "resize" - - # workspace shortcuts - ${wsConfig} - - set $pactl ${config.hardware.pulseaudio.package}/bin/pactl - bindsym XF86AudioRaiseVolume exec $pactl set-sink-volume @DEFAULT_SINK@ +5% - bindsym XF86AudioLowerVolume exec $pactl set-sink-volume @DEFAULT_SINK@ -5% - bindsym XF86AudioMute exec $pactl set-sink-mute @DEFAULT_SINK@ toggle - bindsym XF86AudioMicMute exec $pactl set-source-mute @DEFAULT_SOURCE@ toggle - - set $brightnessctl ${pkgs.brightnessctl}/bin/brightnessctl - bindsym XF86MonBrightnessDown exec $brightnessctl set 5%- - bindsym XF86MonBrightnessUp exec $brightnessctl set +5% - - bindsym $mod+0 exec ${pkgs.swaylock}/bin/swaylock -c FFC0CB -k -l - - font "DejaVu Sans Mono normal 10" - - gaps inner 10 - - output * bg #000000 solid_color - - # class border backgr. text indicator - client.focused #ffffff #ffffff #000000 #d0d0d0 - client.focused_inactive #000000 #000000 #ffffff #000000 - client.unfocused #000000 #000000 #ffffff #000000 - client.urgent #900000 #900000 #ffffff #900000 - - bar { - status_command ${pkgs.i3status}/bin/i3status - position top - colors { - font "DejaVu Sans Mono normal 10" - statusline #ffffff - background #000000 - focused_workspace #ffffff #ffffff #000000 - active_workspace #ffffff #ffffff #c4c4c4 - inactive_workspace #000000 #000000 #ffffff - urgent_workspace #900000 #900000 #ffffff - } - } - ''; - "xdg/i3status/config".text = '' - # TODO(sterni) replace i3status? - general { - output_format = "i3bar" - colors = true - interval = 1 - } - - order += "volume master" - order += "battery all" - order += "tztime dotdate" - order += "tztime dottime" - order += "tztime offset" - - volume master { - format = "πŸ”Š: %volume" - format_muted = "πŸ”ˆ: %volume" - device = "pulse" - } - - battery all { - format = "%status: %percentage" - status_chr = "⚑" - status_bat = "πŸ”‹" - status_unk = "❓" - status_full = "πŸ’―" - low_threshold = 10 - } - - tztime dotdate { - timezone = "UTC" - format = "%Y-%m-%d" - } - - tztime dottime { - timezone = "UTC" - format = "%HΒ·%M" - } - - tztime offset { - format = "%z" - } - ''; + font = { + name = defaultFont; + size = 10; + }; }; vuizvui.programs.foot = { enable = true; settings = { font = [ - "Bitstream Vera Sans Mono" + { + font = defaultFont; + options = { size = 8; }; + } { font = "Noto Color Emoji"; options = { size = 8; }; @@ -287,41 +105,15 @@ in }; }; - environment.variables = { - XKB_DEFAULT_LAYOUT = "de"; - XKB_DEFAULT_VARIANT = "neo"; - # TODO(sterni) user env? - SWAYSOCK = "/run/user/${toString config.users.users.lukas.uid}/sway.sock"; - }; + # notifications + services.dbus.packages = [ pkgs.mako ]; environment.systemPackages = with pkgs; [ - startSway - xdg_utils - networkmanagerapplet # for nm-connection-ediotr - imv zathura - foot - gnome3.nautilus + bemenu # better dmenu + xwayland qt5.qtwayland + wl-clipboard # instead of xsel + grim slurp screenshot # screenshots + mako # notifications ]; - - # allow ydotool to use /dev/uinput - # services.udev.extraRules = '' - # KERNEL=="uinput", GROUP:="uinput", MODE:="0660" - # ''; - # users.groups.uinput = {}; - # users.users.lukas.extraGroups = [ "uinput" ]; - - # based on https://nixos.wiki/Sway - systemd.user = { - services.sway = { - bindsTo = [ "graphical-session.target" ]; - wants = [ "graphical-session-pre.target" ]; - after = [ "graphical-session-pre.target" ]; - serviceConfig = { - Type = "simple"; - ExecStart = "${swayService}/bin/sway-service"; - ExecStop = "${exitSway}/bin/exit-sway"; - }; - }; - }; }; } diff --git a/machines/sternenseemann/wolfgang.nix b/machines/sternenseemann/wolfgang.nix index dc291a07..aeea9b44 100644 --- a/machines/sternenseemann/wolfgang.nix +++ b/machines/sternenseemann/wolfgang.nix @@ -100,11 +100,16 @@ in { audacity signal-desktop tdesktop discord multimc - vuizvui.sternenseemann.t - hunspell vuizvui.profpatsch.nman + vuizvui.sternenseemann.tep + vuizvui.sternenseemann.t + xdg_utils # xdg-open etc. + networkmanagerapplet # for nm-connection-ediotr + imv zathura + gnome3.nautilus firefox-wayland # TODO(sterni) depot.users.sterni.clhs-lookup + hunspell ] ++ (with hunspellDicts; [ de-de en-gb-large en-us ]); services.tor = { diff --git a/modules/module-list.nix b/modules/module-list.nix index 11b6d008..a08b5827 100644 --- a/modules/module-list.nix +++ b/modules/module-list.nix @@ -38,4 +38,5 @@ ./user/profpatsch/programs/weechat.nix ./user/profpatsch/services/bitlbee.nix ./user/profpatsch/services/dunst.nix + ./user/sternenseemann/services/sway.nix ] diff --git a/modules/user/sternenseemann/services/sway.nix b/modules/user/sternenseemann/services/sway.nix new file mode 100644 index 00000000..8a81c41c --- /dev/null +++ b/modules/user/sternenseemann/services/sway.nix @@ -0,0 +1,317 @@ +{ config, pkgs, lib, ... }: + +let + + cfg = config.vuizvui.user.sternenseemann.services.sway; + + inherit (pkgs.vuizvui.profpatsch) + getBins + ; + + bins = (getBins config.hardware.pulseaudio.package [ "pactl" ]) + // (getBins pkgs.dbus [ "dbus-run-session" ]) + // (getBins cfg.package [ "sway" ]) + // (getBins pkgs.i3status [ "i3status" ]) + // (getBins pkgs.brightnessctl [ "brightnessctl" ]) + // (getBins pkgs.swaylock [ "swaylock" ]) + ; + + dpiXresources = pkgs.writeText "Xresources" '' + Xft.dpi: 96 + ''; + + workspaceConfig = lib.concatMapStringsSep "\n" (n: '' + bindsym $mod+${n} workspace number ${n} + bindsym $mod+Shift+${n} move container to workspace number ${n} + '') (builtins.map builtins.toString [ 0 1 2 3 4 5 6 7 8 9 ]); + + additionalBindsConfig = lib.concatStringsSep "\n" + (lib.mapAttrsToList (bind: cmd: '' + bindsym ${bind} exec ${cmd} + '') cfg.additionalBinds); + + mkColorOption = name: default: lib.mkOption { + type = lib.types.str; + description = "${name} color"; + inherit default; + }; + +in { + options = { + vuizvui.user.sternenseemann.services.sway = { + enable = lib.mkEnableOption "sterni's sway"; + + package = lib.mkOption { + type = lib.types.package; + default = pkgs.sway.override { + withBaseWrapper = true; + withGtkWrapper = true; + }; + description = "Sway package to use."; + }; + + menu = lib.mkOption { + type = lib.types.str; + description = "Menu launcher command to use."; + }; + + term = lib.mkOption { + type = lib.types.str; + description = "Terminal emulator command to use."; + }; + + lockArgs = lib.mkOption { + type = with lib.types; listOf str; + description = '' + Arguments to pass to swaylock. + ''; + default = []; + }; + + additionalBinds = lib.mkOption { + type = with lib.types; attrsOf str; + default = {}; + description = '' + Additional key bindings which are appended + to the end of the sway config file. + ''; + }; + + colors = { + background = mkColorOption "background" "#000000"; + active = mkColorOption "active window" "#ffffff"; + inactive = mkColorOption "inactive window" "#000000"; + urgent = mkColorOption "urgent window" "#900000"; + indicate = mkColorOption "indicator" "#d0d0d0"; + }; + + font = { + name = lib.mkOption { + type = lib.types.str; + description = '' + Name of the font to use for bar and window titles. + ''; + default = "monospace"; + }; + + size = lib.mkOption { + type = lib.types.int; + description = '' + Font size to use for bar and window titles. + ''; + default = 12; + }; + }; + + autolaunchFish = lib.mkOption { + type = lib.types.bool; + default = true; + description = '' + Whether to automatically start sway when logging in on tty1. + ''; + }; + }; + }; + + config = lib.mkIf cfg.enable { + programs.fish.loginShellInit = lib.mkIf cfg.autolaunchFish '' + if test -z "$DISPLAY"; and test -z "$WAYLAND_DISPLAY"; and test (tty) = "/dev/tty1" + set -x SWAYSOCK "/run/user/"(id -u)"/sway.sock" + exec ${bins.dbus-run-session} -- ${bins.sway} + end + ''; + + environment.systemPackages = [ + cfg.package + ]; + + environment.sessionVariables = { + # firefox screencapture + XDG_SESSION_TYPE = "wayland"; + XDG_CURRENT_DESKTOP = "sway"; + MOZ_ENABLE_WAYLAND = "1"; + MOZ_USE_XINPUT2 = "1"; + # SDL + SDL_VIDEODRIVER = "wayland"; + # QT + QT_QPA_PLATFORM = "wayland"; + QT_WAYLAND_DISABLE_WINDOWDECORATION = "1"; + # keyboard layout + XKB_DEFAULT_LAYOUT = "de"; + XKB_DEFAULT_VARIANT = "neo"; + }; + + services.pipewire.enable = true; + + xdg.portal = { + enable = true; + extraPortals = with pkgs; [ + xdg-desktop-portal-wlr + xdg-desktop-portal-gtk + ]; + gtkUsePortal = true; + }; + + security.pam.services.swaylock = {}; + + environment.etc = { + "sway/config".text = '' + # correct DPI after hotplugging + exec ${pkgs.xorg.xrdb}/bin/xrdb -load ${dpiXresources} + + # set the one true modifier + set $mod Mod4 + + # neo arrow keys + set $left i + set $right e + set $up l + set $down a + + bindsym $mod+Shift+c reload + + bindsym $mod+Shift+q kill + + bindsym $mod+f fullscreen + + bindsym $mod+h splith + bindsym $mod+v splitv + + bindsym $mod+s layout stacking + bindsym $mod+t layout tabbed + bindsym $mod+n layout toggle split + + # focus + bindsym $mod+Shift+space floating toggle + bindsym $mod+space focus mode_toggle + floating_modifier $mod normal + + bindsym $mod+p focus parent + + bindsym $mod+$left focus left + bindsym $mod+$down focus down + bindsym $mod+$up focus up + bindsym $mod+$right focus right + + # moving + bindsym $mod+Shift+$left move left + bindsym $mod+Shift+$down move down + bindsym $mod+Shift+$up move up + bindsym $mod+Shift+$right move right + + # resizing + mode "resize" { + bindsym $left resize shrink width 10px + bindsym $down resize grow height 10px + bindsym $up resize shrink height 10px + bindsym $right resize grow width 10px + + bindsym Return mode "default" + bindsym Escape mode "default" + } + bindsym $mod+r mode "resize" + + ${workspaceConfig} + + bindsym $mod+u exec ${bins.swaylock} ${lib.escapeShellArgs cfg.lockArgs} + + # volume controls + bindsym XF86AudioRaiseVolume exec ${bins.pactl} set-sink-volume @DEFAULT_SINK@ +5% + bindsym XF86AudioLowerVolume exec ${bins.pactl} set-sink-volume @DEFAULT_SINK@ -5% + bindsym XF86AudioMute exec ${bins.pactl} set-sink-mute @DEFAULT_SINK@ toggle + bindsym XF86AudioMicMute exec ${bins.pactl} set-source-mute @DEFAULT_SOURCE@ toggle + + # brightness controls + bindsym XF86MonBrightnessDown exec ${bins.brightnessctl} set 5%- + bindsym XF86MonBrightnessUp exec ${bins.brightnessctl} set +5% + + # standard launch binds + bindsym $mod+Return exec ${cfg.term} + bindsym $mod+d exec ${cfg.menu} + + ${additionalBindsConfig} + + # aesthetics + font "${cfg.font.name} ${builtins.toString cfg.font.size}" + + # waste some space + gaps inner 10 + + # colors + set $bg ${cfg.colors.background} + set $act ${cfg.colors.active} + set $inact ${cfg.colors.inactive} + set $urg ${cfg.colors.urgent} + set $ind ${cfg.colors.indicate} + + output * bg $bg solid_color + + # class border backgr. text indicator + client.focused $act $act $inact $ind + client.focused_inactive $inact $inact $act $inact + client.unfocused $inact $inact $act $inact + client.urgent $urg $urg $act $urg + + # bar aesthetics + bar { + # TODO(sterni): replace i3status with something betterβ„’ + status_command ${bins.i3status} + position top + colors { + font "${cfg.font.name} ${builtins.toString cfg.font.size}" + statusline $act + background $inact + # type border bg text + focused_workspace $act $act $inact + active_workspace $act $act $ind + inactive_workspace $inact $inact $act + urgent_workspace $urg $urg $act + } + } + ''; + + "xdg/i3status/config".text = '' + general { + output_format = "i3bar" + colors = true + interval = 1 + } + + order += "volume master" + order += "battery all" + order += "tztime dotdate" + order += "tztime dottime" + order += "tztime offset" + + volume master { + format = "πŸ”Š: %volume" + format_muted = "πŸ”ˆ: %volume" + device = "pulse" + } + + battery all { + format = "%status: %percentage" + status_chr = "⚑" + status_bat = "πŸ”‹" + status_unk = "❓" + status_full = "πŸ’―" + low_threshold = 10 + } + + tztime dotdate { + timezone = "UTC" + format = "%Y-%m-%d" + } + + tztime dottime { + timezone = "UTC" + format = "%HΒ·%M" + } + + tztime offset { + format = "%z" + } + ''; + }; + }; +} -- cgit 1.4.1