refactor: add nvidiaCrashFix setting

This commit is contained in:
Youwen Wu 2024-12-31 04:27:39 -08:00
parent efaf10410c
commit 8290649df3
Signed by: youwen5
GPG key ID: 865658ED1FE61EC3
4 changed files with 33 additions and 6 deletions

View file

@ -33,11 +33,25 @@ in
}; };
screenlocker.enable = lib.mkOption { screenlocker.enable = lib.mkOption {
type = lib.types.bool; type = lib.types.bool;
default = cfg.enable; default = cfg.enable && cfg.idleDaemon.enable;
description = '' description = ''
Whether to set up Hyprlock for screen locking. Whether to set up Hyprlock for screen locking.
''; '';
}; };
screenlocker.useNvidiaCrashFix = lib.mkOption {
type = lib.types.bool;
default = osConfig.liminalOS.system.graphics.nvidia.enable;
description = ''
Whether to use a workaround for Hyprlock background blur not working on Nvidia-based machines. Before locking, a screenshot will be taken and placed at `/tmp/__hyprlock-monitor-screenshot.png`.
'';
};
screenlocker.monitor = lib.mkOption {
type = lib.types.nullOr lib.types.string;
default = null;
description = ''
Monitor to use for screen locker. Use `hyprctl monitors` to determine.
'';
};
}; };
config = lib.mkIf cfg.enable { config = lib.mkIf cfg.enable {
@ -330,8 +344,8 @@ in
grace = 1; grace = 1;
}; };
background = { background = {
monitor = ""; monitor = cfg.screenlocker.monitor;
path = "/tmp/__hyprlock-monitor-screenshot.png"; path = lib.mkIf cfg.screenlocker.useNvidiaCrashFix "/tmp/__hyprlock-monitor-screenshot.png";
blur_passes = 3; blur_passes = 3;
blur_size = 7; blur_size = 7;
noise = 0.0117; noise = 0.0117;
@ -378,7 +392,11 @@ in
enable = true; enable = true;
settings = { settings = {
general = { general = {
lock_cmd = "pidof hyprlock || ${pkgs.grim}/bin/grim -o ${config.programs.hyprlock.settings.background.monitor} /tmp/__hyprlock-monitor-screenshot.png && ${pkgs.hyprlock}/bin/hyprlock"; # avoid starting multiple hyprlock instances. lock_cmd =
if cfg.screenlocker.useNvidiaCrashFix then
"pidof hyprlock || ${pkgs.grim}/bin/grim -o ${config.programs.hyprlock.settings.background.monitor} /tmp/__hyprlock-monitor-screenshot.png && ${pkgs.hyprlock}/bin/hyprlock"
else
"pidof hyprlock || hyprlock";
before_sleep_cmd = "loginctl lock-session"; # lock before suspend. before_sleep_cmd = "loginctl lock-session"; # lock before suspend.
after_sleep_cmd = "hyprctl dispatch dpms on"; # to avoid having to press a key twice to turn on the display. after_sleep_cmd = "hyprctl dispatch dpms on"; # to avoid having to press a key twice to turn on the display.
}; };
@ -399,5 +417,13 @@ in
]; ];
}; };
}; };
assertions = [
{
assertion =
!cfg.screenlocker.useNvidiaCrashFix
|| (cfg.screenlocker.useNvidiaCrashFix && cfg.screenlocker.monitor != null);
message = "To use the Nvidia crash fix, you must set screenlocker.monitor to the monitor you want to use as the lock screen that blurs! Use `hyprctl monitors` to determine the monitor codes (should be something like DP-1, HDMI-A-1, etc).";
}
];
}; };
} }

View file

@ -6,5 +6,5 @@
home.stateVersion = "24.05"; home.stateVersion = "24.05";
programs.hyprlock.settings.background.monitor = lib.mkForce "eDP-1"; liminalOS.desktop.hyprland.screenlocker.monitor = "eDP-1";
} }

View file

@ -11,5 +11,5 @@
"HDMI-A-1,1920x1080@60,0x0,1" "HDMI-A-1,1920x1080@60,0x0,1"
]; ];
programs.hyprlock.settings.background.monitor = lib.mkForce "DP-1"; liminalOS.desktop.hyprland.screenlocker.monitor = "DP-1";
} }

View file

@ -13,6 +13,7 @@
liminalOS = { liminalOS = {
utils.easyeffects.enable = true; utils.easyeffects.enable = true;
desktop.hyprland.screenlocker.useNvidiaCrashFix = true;
}; };
programs.git = { programs.git = {