From 8290649df314084a28551b0a197de54e7d69a41f Mon Sep 17 00:00:00 2001 From: Youwen Wu Date: Tue, 31 Dec 2024 04:27:39 -0800 Subject: [PATCH] refactor: add nvidiaCrashFix setting --- .../desktop-environment/hyprland/default.nix | 34 ++++++++++++++++--- reference/hosts/callisto/home.nix | 2 +- reference/hosts/demeter/home.nix | 2 +- reference/users/youwen/hm.nix | 1 + 4 files changed, 33 insertions(+), 6 deletions(-) diff --git a/hm/modules/linux/desktop-environment/hyprland/default.nix b/hm/modules/linux/desktop-environment/hyprland/default.nix index d9c5eca..166d239 100644 --- a/hm/modules/linux/desktop-environment/hyprland/default.nix +++ b/hm/modules/linux/desktop-environment/hyprland/default.nix @@ -33,11 +33,25 @@ in }; screenlocker.enable = lib.mkOption { type = lib.types.bool; - default = cfg.enable; + default = cfg.enable && cfg.idleDaemon.enable; description = '' 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 { @@ -330,8 +344,8 @@ in grace = 1; }; background = { - monitor = ""; - path = "/tmp/__hyprlock-monitor-screenshot.png"; + monitor = cfg.screenlocker.monitor; + path = lib.mkIf cfg.screenlocker.useNvidiaCrashFix "/tmp/__hyprlock-monitor-screenshot.png"; blur_passes = 3; blur_size = 7; noise = 0.0117; @@ -378,7 +392,11 @@ in enable = true; settings = { 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. 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)."; + } + ]; }; } diff --git a/reference/hosts/callisto/home.nix b/reference/hosts/callisto/home.nix index b137741..073c61d 100644 --- a/reference/hosts/callisto/home.nix +++ b/reference/hosts/callisto/home.nix @@ -6,5 +6,5 @@ home.stateVersion = "24.05"; - programs.hyprlock.settings.background.monitor = lib.mkForce "eDP-1"; + liminalOS.desktop.hyprland.screenlocker.monitor = "eDP-1"; } diff --git a/reference/hosts/demeter/home.nix b/reference/hosts/demeter/home.nix index a13e590..04af678 100644 --- a/reference/hosts/demeter/home.nix +++ b/reference/hosts/demeter/home.nix @@ -11,5 +11,5 @@ "HDMI-A-1,1920x1080@60,0x0,1" ]; - programs.hyprlock.settings.background.monitor = lib.mkForce "DP-1"; + liminalOS.desktop.hyprland.screenlocker.monitor = "DP-1"; } diff --git a/reference/users/youwen/hm.nix b/reference/users/youwen/hm.nix index 3d09b36..5da46f3 100644 --- a/reference/users/youwen/hm.nix +++ b/reference/users/youwen/hm.nix @@ -13,6 +13,7 @@ liminalOS = { utils.easyeffects.enable = true; + desktop.hyprland.screenlocker.useNvidiaCrashFix = true; }; programs.git = {