I got this working:
- For the CPU, newest kernel is desirable (6.14)
- The “latest” nvidia driver in nixpkgs is not latest, you need to go to nixos-unstable for it, but you can’t selectively pick a kernel module from unstable while using the stable kernel, so I use
mkDriver
to install 570 directly (see in config below). In the future when newer drivers are stable you should be able to just usepackage = config.boot.kernelPackages.nvidiaPackages.stable;
You can’t use sway as your compositor. That was my main problem. I assumed the compositors wouldn’t have HW compat issues since that’s not how things usually work on X11. Under gnome, everything works fine.- Edit: Turns out you can use sway without disabling nvidia, as long as you tell sway to specifically use the amd card, see next post
- To run a steam game with the nvidia card with this setup you just change your launch options to
nvidia-offload %command%
- For reasons I don’t understand
gamescope
only works with amd though. You can setDRI_PRIME=1
to force amd, which you may expect should be unnecessary since the point of this offload mode is to require an opt-in, but vulkan apps can choose to use whichever card they want anyway, so you may need it. For example the test appvkcube
requires this.
nvidia.nix (import into configuration.nix):
{ config, lib, pkgs, ... }:
{
boot.kernelPackages = pkgs.linuxPackages_6_14;
# Enable OpenGL
hardware.graphics = {
enable = true;
enable32Bit = true;
};
# Load nvidia driver for Xorg and Wayland
services.xserver.videoDrivers = ["nvidia"];
hardware.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 = false;
# 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;
# 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+
open = true;
# Enable the Nvidia settings menu,
# accessible via `nvidia-settings`.
nvidiaSettings = true;
# Optionally, you may need to select the appropriate driver version for your specific GPU.
# package = config.boot.kernelPackages.nvidiaPackages.latest;
package = config.boot.kernelPackages.nvidiaPackages.mkDriver {
version = "570.133.07";
# this is the third one it will complain is wrong
sha256_64bit = "sha256-LUPmTFgb5e9VTemIixqpADfvbUX1QoTT2dztwI3E3CY=";
# unused
sha256_aarch64 = "sha256-2l8N83Spj0MccA8+8R1uqiXBS0Ag4JrLPjrU3TaXHnM=";
# this is the second one it will complain is wrong
openSha256 = "sha256-9l8N83Spj0MccA8+8R1uqiXBS0Ag4JrLPjrU3TaXHnM=";
# this is the first one it will complain is wrong
settingsSha256 = "sha256-XMk+FvTlGpMquM8aE8kgYK2PIEszUZD2+Zmj2OpYrzU=";
# unused
persistencedSha256 = "sha256-4l8N83Spj0MccA8+8R1uqiXBS0Ag4JrLPjrU3TaXHnM=";
};
prime = {
offload = {
enable = true;
enableOffloadCmd = true;
};
# Make sure to use the correct Bus ID values for your system!
amdgpuBusId = "PCI:197:0:0"; # For AMD GPU
nvidiaBusId = "PCI:196:0:0";
};
};
}