From 48007d0a3b13b916ec48c7761d331e392208bece Mon Sep 17 00:00:00 2001 From: alexion Date: Sat, 10 Oct 2026 15:28:24 -0400 Subject: [PATCH] refactor(hyprland): move terminal keybind into registry --- .../nixos/modules/desktop/apps/ghostty.nix | 8 ++++ .../desktop/session/hyprland/default.nix | 15 ++++--- configs/nixos/registry/keybind.nix | 40 +++++++++++++++++++ 3 files changed, 55 insertions(+), 8 deletions(-) create mode 100644 configs/nixos/registry/keybind.nix diff --git a/configs/nixos/modules/desktop/apps/ghostty.nix b/configs/nixos/modules/desktop/apps/ghostty.nix index 2c86617..dd07245 100644 --- a/configs/nixos/modules/desktop/apps/ghostty.nix +++ b/configs/nixos/modules/desktop/apps/ghostty.nix @@ -12,6 +12,14 @@ in options.modules.desktop.apps.ghostty.enable = lib.mkEnableOption "Ghostty as the desktop terminal"; config = lib.mkIf config.modules.desktop.apps.ghostty.enable { + registry.keybind.${config.networking.hostName}.ghostty = { + keys = "SUPER + Return"; + action = { + kind = "exec"; + command = "${pkgs.ghostty}/bin/ghostty"; + }; + }; + home-manager.users.${user}.home.packages = [ pkgs.ghostty ]; }; } diff --git a/configs/nixos/modules/desktop/session/hyprland/default.nix b/configs/nixos/modules/desktop/session/hyprland/default.nix index 86c3874..e73441e 100644 --- a/configs/nixos/modules/desktop/session/hyprland/default.nix +++ b/configs/nixos/modules/desktop/session/hyprland/default.nix @@ -8,6 +8,7 @@ options.modules.desktop.session.hyprland.enable = lib.mkEnableOption "the Hyprland compositor"; config = lib.mkIf config.modules.desktop.session.hyprland.enable { + # This program integration owns the session, portals, and polkit, launched # through the universal Wayland session manager. programs.hyprland = { @@ -34,14 +35,12 @@ settings = { config.general.layout = "dwindle"; - bind = [ - { - _args = [ - "SUPER + Return" - (lib.generators.mkLuaInline ''hl.dsp.exec_cmd("ghostty")'') - ]; - } - ]; + bind = lib.mapAttrsToList (_name: keybind: { + _args = [ + keybind.keys + (lib.generators.mkLuaInline "hl.dsp.exec_cmd(${lib.generators.toLua { } keybind.action.command})") + ]; + }) (lib.attrByPath [ config.networking.hostName ] { } config.registry.keybind); }; }; }; diff --git a/configs/nixos/registry/keybind.nix b/configs/nixos/registry/keybind.nix new file mode 100644 index 0000000..d166ede --- /dev/null +++ b/configs/nixos/registry/keybind.nix @@ -0,0 +1,40 @@ +{ lib, util, ... }: +{ + checks = [ + { + assertion = util.registry.predicates.uniqueValue (entry: { + inherit (entry) host; + inherit (entry.value) keys; + }); + message = "Desktop keybinds must use unique key chords per host."; + } + ]; + + type = lib.types.submodule { + options = { + keys = lib.mkOption { + description = "Sets the key chord for this desktop keybind."; + type = lib.types.str; + example = "SUPER + Return"; + }; + + action = lib.mkOption { + description = "Declares the action this keybind runs."; + type = lib.types.submodule { + options = { + kind = lib.mkOption { + description = "Selects the keybind action kind."; + type = lib.types.enum [ "exec" ]; + }; + + command = lib.mkOption { + description = "Command executed by this keybind."; + type = lib.types.str; + example = "ghostty"; + }; + }; + }; + }; + }; + }; +}