# modules/home/hyprland.nix — Hyprland (Lua config) and the carried shortcuts.
#
# Hyprland 0.56 is configured in Lua (hyprland.lua, `hl.*` API); that is also
# the dialect the carried shortcuts and the toolbox helpers (dropterm, winsnap,
# vault-open, lid-control: `hyprctl dispatch 'hl.dsp…'`) already speak. The
# config is split like the vault's shortcuts/:
# hypr/omarchy.lua the `o` helpers the carried files were written against
# hypr/core.lua monitor, env, look, input, Caelestia layer rules
# hypr/looknfeel.lua the springy animations, shadows, snap, swallow (dotfiles looknfeel.lua)
# hypr/defaults.lua the stock Omarchy binds as captured in keybinds.txt
# hypr/bindings.lua shortcuts/bindings.lua (user overrides, window mode)
# hypr/lid.lua shortcuts/lid.lua
# hypr/caelestia.lua shortcuts/caelestia.lua (Caelestia keys, always on here)
{ ... }:
let theme = import ../_palette.nix; in
{
flake.homeModules.hyprland =
{ config, pkgs, lib, inputs, osConfig, ... }:
let
system = pkgs.stdenv.hostPlatform.system;
hyprPkg = inputs.hyprland.packages.${system}.hyprland;
shellCli = "${config.programs.caelestia.cli.package}/bin/caelestia";
# Small helpers the stock Omarchy binds relied on. They exist only to serve
# this config, so they live here rather than in ~/.local/bin.
helpers = [
# The picker the omarchy-menu-* cheat sheets (bin/) pipe into. Prints the chosen line.
(pkgs.writeShellScriptBin "omarchy-menu-select" ''
title=''${1:-Select}
exec ${pkgs.fuzzel}/bin/fuzzel --dmenu --prompt "$title › " --width 110 --lines 24
'')
# omarchy-not-ported "<bind description>" ["<what it did on Omarchy>"]: an
# honest notification instead of a key that silently does nothing.
(pkgs.writeShellScriptBin "omarchy-not-ported" ''
${pkgs.libnotify}/bin/notify-send -a NixDaemon -t 4000 "$1" "Not set up on this NixOS build.''${2:+ Omarchy: $2}"
'')
(pkgs.writeShellScriptBin "nixdaemon-show" ''
# nixdaemon-show time|battery|calendar|kbd-backlight-cycle
n() { ${pkgs.libnotify}/bin/notify-send -a NixDaemon -t 5000 "$@"; }
case "''${1:-}" in
time) n "$(date '+%H:%M')" "$(date '+%A %-d %B %Y')" ;;
battery) b=/sys/class/power_supply/BAT0; n "Battery $(cat $b/capacity)%" "$(cat $b/status)" ;;
calendar) n "$(date '+%B %Y')" "$(cal | tail -n +2)" ;;
kbd-backlight-cycle)
d=$(ls -d /sys/class/leds/*kbd_backlight 2>/dev/null | head -1); [ -n "$d" ] || exit 0
max=$(cat "$d/max_brightness"); cur=$(cat "$d/brightness"); next=$(( (cur + 1) % (max + 1) ))
${pkgs.brightnessctl}/bin/brightnessctl -q -d "$(basename "$d")" set "$next" ;;
*) echo "usage: nixdaemon-show time|battery|calendar|kbd-backlight-cycle" >&2; exit 2 ;;
esac
'')
# SUPER+K: searchable list of the live binds (what Omarchy's keybindings menu did). Enter copies the key.
(pkgs.writeShellScriptBin "keybinds-menu" ''
sel=$(hyprctl binds -j | ${pkgs.python3}/bin/python3 -I -c '
import json, sys
M = {1: "SHIFT", 4: "CTRL", 8: "ALT", 64: "SUPER"}
rows = set()
for x in json.load(sys.stdin):
mods = "+".join(n for v, n in sorted(M.items()) if x["modmask"] & v)
key = x["key"] or ("code:%d" % x["keycode"])
sub = x.get("submap", "")
rows.add(("%s%s%s %s" % (sub + ": " if sub else "", mods + " + " if mods else "", key, x.get("description", ""))).rstrip())
print("\n".join(sorted(rows)))' | ${pkgs.fuzzel}/bin/fuzzel --dmenu --prompt "Keybindings › " --width 120 --lines 30) || exit 0
[ -n "$sel" ] && printf '%s' "''${sel%% *}" | ${pkgs.wl-clipboard}/bin/wl-copy
'')
# CTRL+SUPER+SPACE: what Omarchy's background switcher did, with Caelestia's
# own wallpaper grid. The launcher shows it when its search starts with
# ">wallpaper ", and there is no IPC for that, so the prefix is typed in.
(pkgs.writeShellScriptBin "wallpaper-picker" ''
c=${shellCli}
case "$($c shell drawers isOpen launcher 2>/dev/null)" in
1|true) exec $c shell drawers toggle launcher ;;
esac
$c shell drawers toggle launcher
sleep 0.25
exec ${pkgs.wtype}/bin/wtype '>wallpaper '
'')
(pkgs.writeShellScriptBin "nightlight-toggle" ''
if pgrep -x hyprsunset >/dev/null; then
pkill -x hyprsunset; ${pkgs.libnotify}/bin/notify-send -a NixDaemon -t 2000 "Night light" "off"
else
${pkgs.hyprsunset}/bin/hyprsunset --temperature 4000 >/dev/null 2>&1 &
${pkgs.libnotify}/bin/notify-send -a NixDaemon -t 2000 "Night light" "on (4000 K)"
fi
'')
];
in
# Only when the Hyprland desktop is switched on (modules/features/desktop/options.nix).
lib.mkIf osConfig.daemon.desktop.hyprland.enable {
wayland.windowManager.hyprland = {
enable = true;
package = hyprPkg; # same derivation NixOS installs; no second copy
portalPackage = null; # programs.hyprland (NixOS) provides the portal
configType = "lua";
systemd.enable = false; # uwsm owns graphical-session.target
xwayland.enable = true;
extraLuaFiles = {
omarchy = { content = ./hypr/omarchy.lua; autoLoad = false; };
core = { content = theme.render (builtins.readFile ./hypr/core.lua); autoLoad = false; };
looknfeel = { content = theme.render (builtins.readFile ./hypr/looknfeel.lua); autoLoad = false; };
defaults = { content = ./hypr/defaults.lua; autoLoad = false; };
bindings = { content = ./hypr/bindings.lua; autoLoad = false; };
lid = { content = ./hypr/lid.lua; autoLoad = false; };
caelestia = { content = ./hypr/caelestia.lua; autoLoad = false; };
};
# Explicit load order: look first, then the stock binds, then the carried files that
# unbind-and-rebind the keys they take over, Caelestia's keys last.
extraConfig = ''
local cfg = (os.getenv("XDG_CONFIG_HOME") or (os.getenv("HOME") .. "/.config")) .. "/hypr"
package.path = cfg .. "/?.lua;" .. package.path
require("omarchy")
require("core")
require("looknfeel")
require("defaults")
require("bindings")
require("lid")
require("caelestia")
'';
};
home.packages = helpers ++ (with pkgs; [
hyprpicker # colour picker (SUPER+PRINT)
hyprsunset # night light
fuzzel # dmenu for the cheat sheets and keybinds-menu
nautilus # the file manager shell.json and the stock binds point at
brightnessctl
pamixer
]); # grim, slurp, wl-clipboard, libnotify: session.nix (shared with Niri)
# The polkit agent, cliphist and udiskie (graphical-session.target) are in
# session.nix: both desktops need them.
}
;
}