Suspend Issue On Prime (NVIDIA + INTEL)

so i’ve configured my nix with prime since my laptop has intel and nvidia GPU. but when i suspend and try to wake up. the screen is just black and i have to restart the laptop to make it work again.
this is how i configured my Prime

intel.nix

{pkgs, ...}: {
  boot = {
    initrd.kernelModules = ["i915"];
  };
  nixpkgs.config.packageOverrides = pkgs: {
    # Avoid using intel-vaapi-driver for newer generations
    intel-vaapi-driver = pkgs.intel-vaapi-driver.override {enableHybridCodec = false;};
  };
  hardware.graphics = {
    # Use hardware.opengl for NixOS versions < 24.11
    enable = true;
    extraPackages = with pkgs; [
      intel-media-driver # LIBVA_DRIVER_NAME=iHD
      intel-vaapi-driver
      libvdpau-va-gl # Optional for VDPAU support
      libva-utils # Optional for VAAPI utilities
      vpl-gpu-rt
    ];
  };
}

nvidia.nix

{
  config,
  pkgs,
  ...
}: {
  boot = {
    initrd.kernelModules = ["nvidia" "nvidia_modeset" "nvidia_uvm" "nvidia_drm"];
    kernelParams = [
      "nvidia-drm.fbdev=1"
      "nvidia.NVreg_PreserveVideoMemoryAllocations=1"
      "acpi_backlight=video"
      "nvidia.NVreg_EnableS0ixPowerManagement=0"

      # "kvm.enable_virt_at_load=0"
    ];
  };
  environment.variables = {
    # GBM_BACKEND = "nvidia-drm"; # If crash in firefox, remove this line
    # LIBVA_DRIVER_NAME = "nvidia"; # hardware acceleration
    __GLX_VENDOR_LIBRARY_NAME = "nvidia";
    NVD_BACKEND = "direct";
  };
  hardware = {
    graphics = {
      enable = true;
      extraPackages = [pkgs.nvidia-vaapi-driver];
    };
    nvidia = {
      # Modesetting is required.
      modesetting.enable = true;

      # Nvidia power management. Experimental, and can cause sleep/suspend to fail.
      # 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 = true;
      };
      # Use the NVidia open source kernel module (not to be confused with the
      # independent third-party "nouveau" open source driver).
      # Support is limited to the Turing and later architectures. Full list of
      # supported GPUs is at:
      # https://github.com/NVIDIA/open-gpu-kernel-modules#compatible-gpus
      # Only available from driver 515.43.04+
      # Currently alpha-quality/buggy, so false is currently the recommended setting.
      open = false;
      forceFullCompositionPipeline = true;
      nvidiaSettings = true;

      # Optionally, you may need to select the appropriate driver version for your specific GPU.
      package = config.boot.kernelPackages.nvidiaPackages.beta;
    };
  };

  services.xserver.videoDrivers = ["nvidia" "displayLink" "vmware"];
}

prime.nix

{
  hardware.nvidia = {
    powerManagement = {
      finegrained = true; # More precise power consumption control
    };

    prime = {
      intelBusId = "PCI:0:2:0";
      nvidiaBusId = "PCI:1:0:0";

      offload = {
        enable = true;
        enableOffloadCmd = true;
      };

      # Make the Intel iGP default. The NVIDIA Quadro is for CUDA/NVENC
      # sync.enable = true;
    };
  };
}

also this what my is my output from pciutils

 fathirbimashabri ~ ❯ nix-shell -p pciutils --run "lspci -nn | grep VGA"
0000:00:02.0 VGA compatible controller [0300]: Intel Corporation Alder Lake-P GT1 [UHD Graphics] [8086:46a3] (rev 0c)
0000:01:00.0 VGA compatible controller [0300]: NVIDIA Corporation AD107M [GeForce RTX 4060 Max-Q / Mobile] [10de:28a0] (rev a1)

 fathirbimashabri ~ ❯ ls -l /dev/dri                                                                                             18:38 
drwxr-xr-x        - root  5 Jan 18:28  by-path
crw-rw----@   226,0 root  5 Jan 18:29 󰡯 card0
crw-rw----@   226,1 root  5 Jan 18:29 󰡯 card1
crw-rw-rw-  226,128 root  5 Jan 18:28 󰡯 renderD128
crw-rw-rw-  226,129 root  5 Jan 18:28 󰡯 renderD129

Do you use CUDA, or would Nouveau be an option to try?

Nah, the issue here is most likely the lack of the power management service - that service is responsible for maintaining graphics memory during sleep on high-memory (i.e., > 256MB, so basically anything newer than ~2012) cards, as the docs explain. It’s disabled by default (the option is called hardware.nvidia.powerManagement.enable) since it’s “experimental”, but it appears to be very much required on high-memory cards.

If you try to switch to a tty and blindly log in from there and then restart your DE/WM there’s a good chance that wipes enough memory that stuff starts rendering again, too. It’s “only” a visual glitch. There are a good dozen posts of people with this exact problem where enabling that option fixed it.

If sleep still doesn’t work after you enable that option, it’s almost certainly an nvidia driver issue and you should report it upstream.


While I’m at it, I’d recommend replacing all the configuration (including the intel stuff) you’ve shared with this:

{ pkgs, lib, ... }: {
  # This *should* be unnecessary, but some DE/WM modules
  # forget to set it, and that makes people think they need
  # `hardware.graphics.enable`.
  #
  # So just to be safe, since you'll blame the rest of the config
  # for failure otherwise...
  services.graphical-desktop.enable = lib.mkDefault true;

  ######################
  # Video acceleration #
  ######################
  environment.sessionVariables.LIBVA_DRIVER_NAME = "iHD";

  hardware.graphics.extraPackages = with pkgs; [
    # Yes, you only need this, I don't know why the internet
    # insists on adding all those other packages here, they
    # either do nothing or they actively break vaapi
    intel-media-driver
  ];

  ##################
  #  Using nvidia  #
  ##################

  services.xserver.videoDrivers = [ "nvidia" ];

  hardware.nvidia = {
    open = true;

    powerManagement = {
      enable = true;
      finegrained = true;
    };

    # Note that these settings don't do *anything* if you're using wayland.
    # If you *are* using wayland you can just delete all of this; whatever
    # your primary GPU is will always be your primary GPU, assuming
    # your firmware doesn't change its mind about which GPU to default
    # to - if you want control over that, see my answer to this other post:
    #
    # https://discourse.nixos.org/t/why-nixos-using-dgpu-instead-of-igpu/73973/2?u=tlater
    prime = {
      intelBusId = "PCI:0:2:0";
      nvidiaBusId = "PCI:1:0:0";

      offload = {
        enable = true;
        enableOffloadCmd = true;
      };
    };
  };
}

There are a number of posts around where I go into detail about the rationale behind these settings, but people always feed this into LLMs and get the same garbage they copied from the NixOS wiki and then argue with me about it, so I don’t think I’ll bother explaining again; feel free to search my post history instead.

1 Like