From 10582a5727dc31e9bd519c2bf6029bfc9300aaec Mon Sep 17 00:00:00 2001 From: Doloro1978 Date: Wed, 3 Dec 2025 10:42:03 +0000 Subject: [PATCH] qol(Hibernate/Sleep): Now works :tada: --- nix/hosts/doloro/nixos.nix | 3 +- nix/modules/hyprland/home.nix | 95 +++++++++++++++++++++++++++------- nix/modules/hyprland/nixos.nix | 13 +++++ 3 files changed, 90 insertions(+), 21 deletions(-) diff --git a/nix/hosts/doloro/nixos.nix b/nix/hosts/doloro/nixos.nix index a8b8493..611ff21 100644 --- a/nix/hosts/doloro/nixos.nix +++ b/nix/hosts/doloro/nixos.nix @@ -126,11 +126,12 @@ in # Enable this if you have graphical corruption issues or application crashes after waking # up from sleep. This fixes it by saving the entire VRAM memory to /tmp/ instead # of just the bare essentials. - powerManagement.enable = false; + powerManagement.enable = true; # Fine-grained power management. Turns off GPU when not in use. # Experimental and only works on modern Nvidia GPUs (Turing or newer). powerManagement.finegrained = false; + # prime.offload.enable = true; # Use the NVidia open source kernel module (not to be confused with the # independent third-party "nouveau" open source driver). diff --git a/nix/modules/hyprland/home.nix b/nix/modules/hyprland/home.nix index 5c5b5ba..1f04e1f 100644 --- a/nix/modules/hyprland/home.nix +++ b/nix/modules/hyprland/home.nix @@ -7,6 +7,18 @@ }: let cfg = config.modules.Hyprland; + suspend = pkgs.writeShellScript "hyprland_suspend" '' + #!/bin/bash + + case "$1" in + suspend) + killall -STOP Hyprland + ;; + resume) + killall -CONT Hyprland + ;; + esac + ''; in { imports = [ @@ -17,33 +29,76 @@ in options.modules.Hyprland = { enable = lib.mkEnableOption "Hyprland"; }; - config.wayland.windowManager.hyprland = lib.mkIf cfg.enable { - enable = true; - # set the flake package - # settings = { }; - systemd.variables = [ "--all" ]; - package = inputs.hyprland.packages.${pkgs.stdenv.hostPlatform.system}.hyprland; - portalPackage = - inputs.hyprland.packages.${pkgs.stdenv.hostPlatform.system}.xdg-desktop-portal-hyprland; - }; # TODO, split this into its own module; - config.programs = lib.mkIf cfg.enable { - wlogout = { + config = lib.mkIf cfg.enable { + wayland.windowManager.hyprland = { enable = true; + # set the flake package + # settings = { }; + systemd.variables = [ "--all" ]; + package = inputs.hyprland.packages.${pkgs.stdenv.hostPlatform.system}.hyprland; + portalPackage = + inputs.hyprland.packages.${pkgs.stdenv.hostPlatform.system}.xdg-desktop-portal-hyprland; }; - foot = { - enable = true; - settings = { - main = { - term = "xterm-256color"; + programs = { + wlogout = { + enable = true; + }; + foot = { + enable = true; + settings = { + main = { + term = "xterm-256color"; - font = "CaskaydiaCove Nerd Font Mono:size=12"; - }; + font = "CaskaydiaCove Nerd Font Mono:size=12"; + }; - mouse = { - hide-when-typing = "yes"; + mouse = { + hide-when-typing = "yes"; + }; }; }; }; + systemd.user.services."hyprland_suspend" = { + Unit = { + Description = "Suspend hyprland"; + Before = [ + "systemd-suspend.service" + "systemd-hibernate.service" + "nvidia-suspend.service" + "nvidia-hibernate.service" + ]; + }; + Install = { + WantedBy = [ + "systemd-suspend.service" + "systemd-hibernate.service" + ]; + }; + Service = { + Type = "oneshot"; + ExecStart = "${suspend} suspend"; + }; + }; + systemd.user.services."hyprland_resume" = { + Unit = { + Description = "Resume hyprland"; + After = [ + "systemd-suspend.service" + "systemd-hibernate.service" + "nvidia-resume.service" + ]; + }; + Install = { + WantedBy = [ + "systemd-suspend.service" + "systemd-hibernate.service" + ]; + }; + Service = { + Type = "oneshot"; + ExecStart = "${suspend} resume"; + }; + }; }; } diff --git a/nix/modules/hyprland/nixos.nix b/nix/modules/hyprland/nixos.nix index 7626197..014e441 100644 --- a/nix/modules/hyprland/nixos.nix +++ b/nix/modules/hyprland/nixos.nix @@ -14,6 +14,19 @@ in }; config = lib.mkIf cfg.enable { programs.xwayland.enable = true; + boot.kernelParams = [ + "resume=UUID=d9b81619-5772-4ac4-bcd5-552e1e784f9e" + "resume_offset=141042944" + ]; + boot.resumeDevice = "/dev/disk/by-uuid/d9b81619-5772-4ac4-bcd5-552e1e784f9e"; + powerManagement.enable = true; + swapDevices = [ + # [[ Hibernate ]] + { + device = "/var/lib/swapfile"; + size = 48 * 1024; # 48GB in MB + } + ]; programs.hyprland = { enable = true; # set the flake package