{ pkgs, config, lib, ... }: let cfg = config.grimmShared; in { config = let waybar_full = pkgs.writeShellScriptBin "waybar-full" ( (lib.getExe config.programs.waybar.package) + (if isNull cfg.sway.bar.config then "" else " -c ${cfg.sway.bar.config}") + (if isNull cfg.sway.bar.style then "" else " -s ${cfg.sway.bar.style}") ); bar_config = '' bar { swaybar_command ${lib.getExe waybar_full} } ''; build_conf = with lib; sway_conf: let build_definition_lines = mapAttrsToList (name: value: "set \$${name} ${value}"); build_keybind_lines = mapAttrsToList (key: value: "bindsym ${key} ${value}"); build_exec_lines = map (item: "exec " + (if isString item then item else (getExe item))); build_mode_lines = mapAttrsToList (name: value: '' mode "${name}" { ${strings.concatLines (map (item: " " + item ) (build_conf value))}}''); in ([ ] ++ (build_definition_lines sway_conf.definitions) ++ (build_keybind_lines sway_conf.keybinds) ++ (build_exec_lines sway_conf.autolaunch) ++ (build_mode_lines sway_conf.modes) ++ optional (sway_conf.extraConfig != "") sway_conf.extraConfig ); text = lib.concatLines ( (build_conf cfg.sway.config) ++ lib.optional cfg.sway.bar.enable bar_config ++ (lib.mapAttrsToList (name: value: "output ${value.id} mode ${value.mode}@${toString value.fps}Hz" + (lib.optionalString (value.pos != null) " position ${value.pos}") ) cfg.screens) ); sway_conf = pkgs.writeText "sway.conf" text; in with cfg; lib.mkIf (enable && sway.enable) { environment.etc."sway.conf" = { source = sway_conf; }; environment.systemPackages = [ waybar_full ] ++ (with pkgs; [ procps slurp libnotify ]); systemd.services.reload-sway = { description = "Reload all running sway instances"; wantedBy = [ "multi-user.target" ]; serviceConfig.Type = "oneshot"; script = '' for pid in $(${pkgs.procps}/bin/pgrep sway -x) do uid=$(id -u $(${pkgs.procps}/bin/ps -o user= -p $pid)) export SWAYSOCK="/run/user/$uid/sway-ipc.$uid.$pid.sock" if [[ -e "$SWAYSOCK" ]] ; then echo "sock is $SWAYSOCK" ${config.programs.sway.package}/bin/swaymsg reload fi done ''; reloadTriggers = [ text ]; }; programs.waybar.enable = true; programs.sway = { enable = true; wrapperFeatures = { gtk = true; base = true; }; extraPackages = with pkgs; [ swaylock swayidle wl-clipboard wf-recorder dmenu wmenu waybar-mpris ]; extraOptions = [ "--unsupported-gpu" "--config" "/etc/sway.conf" ]; extraSessionCommands = '' export XDG_CURRENT_DESKTOP=sway export SDL_VIDEODRIVER=wayland export QT_QPA_PLATFORM=wayland export QT_WAYLAND_DISABLE_WINDOWDECORATION="1" export _JAVA_AWT_WM_NONREPARENTING=1 export MOZ_ENABLE_WAYLAND=1 # export WLR_RENDERER=vulkan # export DRI_PRIME=1 # export MESA_LOADER_DRIVER_OVERRIDE="zink" ''; }; }; }