Suspend/resume cycling on system resume

I might have found something. Based on this post [Solved] Suspend is failing with nvidia and wayland. / Newbie Corner / Arch Linux Forums

I added this to my configuration.nix:

  systemd = {
     services."gnome-suspend" = {
      description = "suspend gnome shell";
      before = [
        "systemd-suspend.service" 
        "systemd-hibernate.service"
        "nvidia-suspend.service"
        "nvidia-hibernate.service"
      ];
      wantedBy = [
        "systemd-suspend.service"
        "systemd-hibernate.service"
      ];
      serviceConfig = {
        Type = "oneshot";
        ExecStart = ''${pkgs.procps}/bin/pkill -f -STOP ${pkgs.gnome-shell}/bin/gnome-shell'';
      };
    };
    services."gnome-resume" = {
      description = "resume gnome shell";
      after = [
        "systemd-suspend.service" 
        "systemd-hibernate.service"
        "nvidia-resume.service"
      ];
      wantedBy = [
        "systemd-suspend.service"
        "systemd-hibernate.service"
      ];
      serviceConfig = {
        Type = "oneshot";
        ExecStart = ''${pkgs.procps}/bin/pkill -f -CONT ${pkgs.gnome-shell}/bin/gnome-shell'';
      };
    };
  };

I have tested it a couple of times, no more suspend/resume cycles for me with power management enabled, well at least for now, I hope it stays this way.

Also I think for this to work you need to add killall to your installed packages if you haven’t. Don’t know why it isn’t there by default but whatever. EDIT: it seems pkill is the tool of choice these days. I changed the script to use that and also specified the exact name of the gnome-shell process.

Can someone check if this works?

4 Likes