{
  lib,
  pkgs,
  config,
  ...
}: let
  cfg = config.programs.menu;
  terminal = config.programs.terminal;
  termcmd = "${terminal}/bin/${terminal.pname}";
  menucmd = config.programs.menu.drunCommand;
  inherit (lib) mkPackageOption mkOption;
in {
  options.programs = {
    menu = {
      package = mkPackageOption pkgs "wofi" {
        example = "pkgs.dmenu-wayland";
      };
      dmenuCommand = mkOption {
        default = "/bin/wofi --show dmenu";
        example = "/bin/dmenu";
      };
      drunCommand = mkOption {
        default = "/bin/wofi --show drun";
      };
    };
  };

  config = {
    programs.wofi = lib.mkIf (cfg.package == pkgs.wofi) {
      enable = true;
      settings = {
        term = termcmd;
        insensitive = true;
      };
    };

    wayland.windowManager.sway.config.menu = menucmd;

    home.packages = [cfg.package];
  };
}
