Files
dev/configs/nixos/modules/desktop/session/rofi.nix

63 lines
1.9 KiB
Nix

{
config,
lib,
pkgs,
...
}:
# rofi as the desktop launcher and dmenu-style menu frontend.
let
execBind = key: command: {
_args = [
key
(luaCall "hl.dsp.exec_cmd" [ command ])
];
};
luaCall =
function: args:
lib.generators.mkLuaInline "${function}(${lib.concatMapStringsSep ", " toLua args})";
user = config.user.name;
# A session menu built on the same themed rofi, so the power actions look
# like every other menu the launcher drives.
powerMenu = pkgs.writeShellScript "rofi-power-menu" ''
chosen=$(printf '%s\n' Lock Suspend 'Log out' Reboot 'Shut down' \
| ${pkgs.rofi}/bin/rofi -dmenu -i -p Power)
case "$chosen" in
Lock) ${pkgs.systemd}/bin/loginctl lock-session ;;
Suspend) ${pkgs.systemd}/bin/systemctl suspend ;;
'Log out') ${pkgs.systemd}/bin/loginctl terminate-session "$XDG_SESSION_ID" ;;
Reboot) ${pkgs.systemd}/bin/systemctl reboot ;;
'Shut down') ${pkgs.systemd}/bin/systemctl poweroff ;;
esac
'';
toLua = lib.generators.toLua { };
in
{
options.modules.desktop.session.rofi.enable = lib.mkEnableOption "the rofi launcher";
config = lib.mkIf config.modules.desktop.session.rofi.enable {
home-manager.users.${user} = {
# No theme is set here: Stylix's rofi target supplies the Nord one.
programs.rofi = {
enable = true;
# Application launch is the only mode, kept minimal so the prompt opens
# as fast as rofi can read the desktop entries.
# Icons are off: resolving one per entry is the bulk of drun's startup.
extraConfig = {
modi = "drun";
show-icons = false;
};
};
# The launcher and the session menu, kept next to the tool they drive.
wayland.windowManager.hyprland.settings.bind = [
(execBind "SUPER + R" "${pkgs.rofi}/bin/rofi -show drun")
(execBind "SUPER + SHIFT + X" "${powerMenu}")
];
};
};
}