From fddec1412881ab2839c9061034d06259935d3b55 Mon Sep 17 00:00:00 2001 From: alexion Date: Sat, 10 Oct 2026 15:41:32 -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 | 37 +++++++++++++++++++ src/dotfiles/util.nix | 13 ++++++- 4 files changed, 63 insertions(+), 10 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..be55051 --- /dev/null +++ b/configs/nixos/registry/keybind.nix @@ -0,0 +1,37 @@ +{ lib, util, ... }: +{ + checks = [ + { + assertion = util.registry.predicates.uniquePerHost (entry: 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"; + }; + }; + }; + }; + }; + }; +} diff --git a/src/dotfiles/util.nix b/src/dotfiles/util.nix index 5f87cff..b461c7c 100644 --- a/src/dotfiles/util.nix +++ b/src/dotfiles/util.nix @@ -16,14 +16,23 @@ let [ ] ) (builtins.readDir dir) ); + + uniqueValue = + value: entries: builtins.length (lib.unique (map value entries)) == builtins.length entries; in { inherit collectNixFiles; removeNixSuffix = path: lib.removeSuffix ".nix" (builtins.baseNameOf path); - registry.predicates.uniqueValue = - value: entries: builtins.length (lib.unique (map value entries)) == builtins.length entries; + registry.predicates.uniqueValue = uniqueValue; + + registry.predicates.uniquePerHost = + value: + uniqueValue (entry: { + inherit (entry) host; + value = value entry; + }); bridgeName = id: "br-vlan${toString id}";