Files
nixos-configs/hosts/pinwheel/modules/hyprlock/default.nix
T
Alexander Heldt 48248e8c7d pinwheel: Lock instead of suspend on lid close
Have logind ignore the lid switch and suspend/hibernate keys so the
machine stays reachable over SSH with the lid closed. SUPER + SHIFT + x
remains the way to suspend; closing the lid now only locks the screen.
2026-10-22 19:37:42 +02:00

112 lines
2.9 KiB
Nix

{
pkgs,
lib,
config,
...
}:
let
enabled = config.mod.hyprlock.enable;
hyprlandEnabled = config.mod.hyprland.enable;
in
{
options = {
mod.hyprlock = {
enable = lib.mkEnableOption "enable hyprlock module";
dpmsTimeout = lib.mkOption {
description = "timeout in seconds before DPMS is turned on";
type = lib.types.str;
default = "10";
};
};
};
config = lib.mkIf enabled {
home-manager.users.alex = {
programs.hyprlock = {
enable = true;
settings = {
general = {
hide_cursor = true;
};
background = [
{
color = "rgb(000000)";
}
];
input-field = [
{
size = "250, 50";
position = "0, 0";
halign = "center";
valign = "center";
outline_thickness = 2;
dots_center = true;
fade_on_empty = false;
placeholder_text = "";
}
];
};
};
wayland.windowManager.hyprland = lib.mkIf hyprlandEnabled {
settings = {
bind =
let
pause-music = "${pkgs.playerctl}/bin/playerctl -a pause";
dpmsTimeout = config.mod.hyprlock.dpmsTimeout;
dpmsOff = pkgs.writeShellScript "dpms-off" ''
${pkgs.hyprland}/bin/hyprctl dispatch 'hl.dsp.dpms({ action = "off" })'
'';
dpmsOn = pkgs.writeShellScript "dpms-on" ''
${pkgs.hyprland}/bin/hyprctl dispatch 'hl.dsp.dpms({ action = "on" })'
'';
dpms-lock = pkgs.writeShellScript "dpms-lock" ''
${pkgs.swayidle}/bin/swayidle \
timeout ${dpmsTimeout} ${dpmsOff} \
resume ${dpmsOn} &
${pkgs.hyprlock}/bin/hyprlock; ${pkgs.procps}/bin/pkill swayidle
'';
in
[
{
_args = [
"SUPER + x"
(lib.generators.mkLuaInline ''hl.dsp.exec_cmd("${pause-music}; ${dpms-lock}")'')
];
}
{
_args = [
"switch:on:Lid Switch"
(lib.generators.mkLuaInline ''hl.dsp.exec_cmd("${pkgs.procps}/bin/pidof hyprlock || { ${pause-music}; ${dpms-lock}; }")'')
{ locked = true; }
];
}
{
_args = [
"SUPER + SHIFT + x"
(lib.generators.mkLuaInline
''hl.dsp.exec_cmd("${pause-music}; ${pkgs.hyprlock}/bin/hyprlock & sleep 0.5; systemctl suspend")''
)
];
}
];
};
};
};
security = {
polkit.enable = true;
pam.services.hyprlock = {};
};
};
}