{
  config,
  lib,
  pkgs,
  ...
}:

let
  start_sway_session = pkgs.writeTextFile {
    name = "start_sway_session.conf";
    text = ''
      # Trigger graphical-session.target through sway-session.target so systemd user units can depend on it.
      exec systemctl --user start sway-session.target
      exec swaymsg -t subscribe '["shutdown"]' && systemctl --user stop sway-session.target
    '';
  };
in
{
  imports = [ ];

  config = lib.mkIf (config.me.graphical && config.me.sway.enable) {
    me.swayIncludes = lib.mkAfter [
      start_sway_session
    ];
  };
}
