{
  pkgs,
  lib,
  config,
  inputs,
  ...
}:
let
  inherit (lib)
    range
    nameValuePair
    mapAttrs'
    mergeAttrsList
    ;
  inherit (builtins) listToAttrs replaceStrings;
  inherit (config.hm.lib.niri) actions;
  hBinds = {
    H = "left";
    L = "right";
  };
  vBinds = {
    J = "down";
    K = "up";
  };
  makeDirBind =
    mods: cmd: keys:
    mapAttrs' (
      key: dir:
      nameValuePair "${mods}+${key}" {
        action = actions."${replaceStrings [ "$DIR" ] [ "${dir}" ] "${cmd}"}";
      }
    ) keys;
  makeWsBind =
    mods: cmd:
    listToAttrs (
      map (num: {
        name = "${mods}+${builtins.toString num}";
        value = {
          action."${cmd}" = num;
        };
      }) (range 1 6)
    );
  tagctl = lib.getExe' inputs.niri-tag.packages.${pkgs.system}.unstable "tagctl";
  makeTagBind =
    mods: cmd:
    listToAttrs (
      map (num: {
        name = "${mods}+${builtins.toString num}";
        value = {
          action.spawn = [
            tagctl
            cmd
            (builtins.toString num)
          ];
        };
      }) (range 1 6)
    );
in
{
  hm.programs.niri.settings.binds = mergeAttrsList [
    {
      "Mod+D".action.spawn = [
        "qs"
        "ipc"
        "call"
        "launch"
        "toggle"
      ];
      "Mod+F".action.spawn = "firefox";
      "Mod+E".action.spawn = "nautilus";
      "Mod+Return".action.spawn = "kitty";
      "Mod+Shift+E".action.spawn = "wlogout";
      "Mod+Equal".action.spawn = "bitwarden";
      "Mod+Shift+Q".action = actions.close-window;
      "Mod+Shift+S".action = actions.screenshot;
      "Mod+R".action = actions.switch-preset-column-width;
      "Mod+Shift+R".action = actions.maximize-column;
      "XF86AudioRaiseVolume".action.spawn = [
        "volumectl"
        "-u"
        "up"
      ];
      "XF86AudioLowerVolume".action.spawn = [
        "volumectl"
        "-u"
        "down"
      ];
      "XF86AudioMute".action.spawn = [
        "volumectl"
        "toggle-mute"
      ];
      "XF86AudioStop".action.spawn = [
        "playerctl"
        "stop"
      ];
      "XF86AudioPlay".action.spawn = [
        "playerctl"
        "play-pause"
      ];
      "XF86AudioNext".action.spawn = [
        "playerctl"
        "next"
      ];
      "XF86AudioPrev".action.spawn = [
        "playerctl"
        "previous"
      ];
      "Mod+Space".action = actions.toggle-window-floating;
    }
    (makeDirBind "Mod" "focus-window-$DIR" vBinds)
    (makeDirBind "Mod" "focus-column-or-monitor-$DIR" hBinds)
    (makeDirBind "Mod+Shift" "move-column-$DIR-or-to-monitor-$DIR" hBinds)
    (makeDirBind "Mod+Ctrl" "consume-or-expel-window-$DIR" hBinds)
    (makeDirBind "Mod+Ctrl" "move-window-$DIR" vBinds)
    (makeTagBind "Mod" "toggle-tag")
    (makeTagBind "Mod+Shift" "toggle")
    (makeTagBind "Mod+Ctrl" "exclusive-tag")
  ];
}
