nixos-config/modules/programs/sway/default.nix

130 lines
4.3 KiB
Nix

{
config
, lib, pkgs
, stdenv
, ...
}:
let
modifier = "Mod1";
writeShellScript = pkgs.writeShellScript;
nwggrid = "${pkgs.nwg-launchers}/bin/nwggrid";
gopass = "${pkgs.gopass}/bin/gopass";
# TODO: Add shebangs
passwordDmenu = writeShellScript "password_menu" ''
password=$(${gopass} list --flat | ${pkgs.bemenu}/bin/bemenu)
${gopass} show -c "$password"
'';
mkWrapperScript = binary: args: let
pname = baseNameOf binary;
in writeShellScript "${pname}-wrapper" ''
ps -aux | grep ${pname} &> /dev/null
[[ "$?" -eq 0 ]] && pkill ${pname}
${binary} ${args}
'';
swayncWrapper = mkWrapperScript "${pkgs.swaync}/bin/swaync" "";
waybarWrapper = mkWrapperScript "${pkgs.waybar}/bin/waybar" "";
kanshiWrapper = mkWrapperScript "${pkgs.kanshi}/bin/kanshi" "";
nwggridWrapper = mkWrapperScript "${pkgs.nwg-launchers}/bin/nwggrid-server" "";
# TODO: Fuse this with kanshi
swayIdleWrapper = mkWrapperScript "${pkgs.swayidle}/bin/swayidle" "-w before-sleep '${pkgs.swaylock}/bin/swaylock -f --image $(find ~/Data/Wallpaper/horizontal/ -maxdepth 1 -type f | shuf -n 1)'";
cfg = config.ptw.programs.sway;
in {
options.ptw.programs.sway = {
enable = lib.mkEnableOption "Configure sway using HomeManager";
extraSessionCommands = lib.mkOption {
description = "Commands to be run before sway is started. See programs.sway.extraSessionCommands";
default = "";
};
};
config = lib.mkIf cfg.enable {
xdg.portal = {
enable = true;
extraPortals = [
pkgs.xdg-desktop-portal-wlr
];
};
qt5.style = "adwaita-dark";
environment = {
systemPackages = with pkgs; [ adwaita-qt wdisplays ];
sessionVariables = {
# sway
#"_JAVA_AWT_NONREPARENTING" = 1;
# Wayland
"QT_QPA_PLATFORM" = "wayland-egl";
"ECORE_EVAS_ENGINE" = "wayland-egl";
"ELM_ENGINE" = "wayland-egl";
"SDL_VIDEODRIVER" = "wayland";
};
};
programs.sway = {
enable = true;
extraSessionCommands = cfg.extraSessionCommands;
};
home-manager.users."${config.ptw.system.singleUser}" = {
wayland.windowManager.sway = {
enable = true;
extraSessionCommands = cfg.extraSessionCommands;
config = {
bars = [ ];
startup = [
{ command = "${nwggridWrapper}"; always = true; }
{ command = "${swayncWrapper}"; always = true; }
{ command = "${waybarWrapper}"; always = true; }
{ command = "${kanshiWrapper}"; always = true; }
{ command = "${pkgs.polkit_gnome}/libexec/polkit-gnome-authentication-agent-1"; always = true; }
{ command = "${swayIdleWrapper}"; always = true; }
] ++ lib.optional config.ptw.system.i18n.enable {
command = "${pkgs.fcitx5}/bin/fcitx5 -d";
always = true;
};
modifier = "${modifier}";
gaps = {
inner = 5;
outer = 7;
};
input = {
"*" = { xkb_layout = "de"; };
"2:7:SynPS/2_Synaptics_TouchPad" = {
tap = "enabled";
natural_scroll = "disabled";
dwt = "enabled";
};
"2:10:TPPS/2_Elan_TrackPoint" = { dwt = "enabled"; };
};
# NOTE: Somehow the cursor sometimes lags a bit
#output = {
# "*" = { adaptive_sync = "on"; };
#};
keybindings = let
speakers = "alsa_output.pci-0000_00_1f.3.analog-stereo";
in lib.mkOptionDefault {
"${modifier}+Return" = "exec alacritty";
"${modifier}+e" = "exec emacs";
"${modifier}+Shift+q" = "kill";
"${modifier}+f" = "exec firefox";
"${modifier}+d" = "exec ${pkgs.nwg-launchers}/bin/nwggrid -client";
"${modifier}+p" = "exec ${passwordDmenu}";
"Mod4+s" = "exec systemctl suspend";
# TODO: Screenlock
#"Mod4+l" = "exec ..."
"F1" = "exec pactl set-sink-volume ${speakers} toggle";
"F2" = "exec pactl set-sink-volume ${speakers} -10%";
"F3" = "exec pactl set-sink-volume ${speakers} +10%";
"F5" = "exec brightnessctl --device=intel_backlight set 10%-";
"F6" = "exec brightnessctl --device=intel_backlight set +10%";
};
};
};
};
};
}