{ pkgs
, lib
, config
, ... }: with lib; let
  cfg = config.passthrough.headless;
in mkIf (cfg.enable != null) {
  wayland.windowManager.sway.config = {
    output = {
      ${cfg.enable}.pos = "0 0";
      HEADLESS-1 = cfg.output;
    };

    startup = [ { command = "swaymsg create_output && swaymsg output HEADLESS-1 disable"; } ];
  };

  home.packages = [ (pkgs.writeShellScriptBin "headless" ''
    swaymsg output HEADLESS-1 enable
    ${pkgs.wayvnc}/bin/wayvnc \
      --output=HEADLESS-1 \
      ${cfg.extraArgs} \
      ${cfg.host} ${toString cfg.port}
    swaymsg output HEADLESS-1 disable
  '') ];
}
