Back to blog
3 min read

Better keybinds with Hyprland and NixOS

Declarative configs: less repetition, more bragging.

Hyprland gets it. It gives you the power to truly configure and control your own computer.

Nix gets it too. Everything is data. Structured data that can be composed, committed and backed up.

I would like to show you my use case, which showcases the advantages of both - keybinds:

  • defined in Nix, so they are shareable and backed up via git,
  • just Plain old data™, so I can work with it as I please. For example, list keybinds in a cheat-sheet.

Keybinds

I've been puzzled for some time now: why is customization not popular? I am not sure I know a person that would make their own keybinds. Each person can answer that one for themselves. As for me, I guess I just never thought about computers that way. Windows gave me clicking so I clicked.

But then, Linux opened my eyes. It is My computer. I can adapt it for me. It is My time I am protecting here. And now, I do not even think about my favourite keybinds. I just control the computer. I am flying.

Food for thought. Do you...

  • launch the same four applications all day, every day?
  • click, or worse, search for the programs every time?
  • screenshot often?
  • swipe through desktops and alt+tab windows until you find the one you are looking for?

I cannot unsee the waste of effort now. Please, consider keybinds!

Keybinds in Nix and Hyprland

Now that I've hopefully sold you on keybinds, let me plant one more seed in your head. Let's say you use keybinds and you are happy with them.

Have you considered what surrounds your keybinds?

  • Do you use two computers? If so, how do you synchronize the keybinds?
  • Do you want to reinstall the computer? Upgrade an SSD? How do you back up the keybinds?
  • Do you want the keybind to only register if a certain program is installed on your computer?
  • Can you programmatically control your PC? Move programs, change brightness, ...

All that and more is something Nix and Hyprland can provide for you.

It is time we take a quick look at a bit of code.

The options below come from my own Nix module.

This binding opens my configured terminal when I press Super + Enter. defaultTerminal holds the terminal command.

michal.programs.hyprland.keybinds = [  {    description = "Launch terminal";    bind = {      mods = ["SUPER"];      key = "Return";    };    command = {exec = defaultTerminal;};  }];

The description, key combination and command are separate fields. I can export the same definitions to JSON and work with them as data. Here is an excerpt of this binding:

[  {    "description": "Launch terminal",    "bind": {      "mods": [        "SUPER"      ],      "key": "Return"    }  }]

This opens up plenty of integration possibilities. My cheat sheet can read the descriptions and key combinations from this JSON, so I can change a binding without updating a second copy by hand. Other tools could use the same data to search my shortcuts or generate documentation.

See the full implementation in my keybinds module.

In conclusion

The article is about keybinds. But not really - it is about much more: Customization and actively thinking about your environment.

Agents do the hard part for you now! Invest a minute and run the following prompt:

Hello my favorite agent.Take a look through my computer, my behavior,previous conversations etc. and suggest a couple of keybindsthat will save me the most time.Thanks.