NixDaemon

NixOS pentest workstation as one flake — IceBreaker's successor
git clone https://git.daemon-sec.xyz/NixDaemon.git
Log | Files | Refs | README

nvidia.nix (2430B)


      1 # modules/hosts/laptop/nvidia.nix
      2 #
      3 # The panel (eDP-1) is wired to the RTX 3070 Ti at 01:00.0: the firmware MUX is
      4 # in discrete mode (amdgpu's eDP-2 reports disconnected). Linux cannot change
      5 # the MUX, so this configures what the hardware presents: NVIDIA open kernel
      6 # module with modesetting, the Radeon 680M left as a secondary DRM device.
      7 #
      8 # PARKED: if the MUX is switched to hybrid in the BIOS, swap the AQ_DRM_DEVICES
      9 # order (igpu-card first) and add the prime offload block at the bottom.
     10 { ... }:
     11 {
     12   flake.nixosModules.laptop-nvidia =
     13   { config, pkgs, lib, ... }:
     14   {
     15     services.xserver.videoDrivers = [ "nvidia" ];
     16 
     17     hardware.graphics = {
     18       enable = true;
     19       extraPackages = [ pkgs.nvidia-vaapi-driver ];
     20     };
     21 
     22     hardware.nvidia = {
     23       open = true; # GA104 is supported by the open kernel modules
     24       modesetting.enable = true; # nvidia-drm.modeset=1
     25       package = config.boot.kernelPackages.nvidiaPackages.stable;
     26       nvidiaSettings = false;
     27       # powerManagement.enable = true;  # suspend/resume helpers; untested on this laptop, left at default
     28     };
     29 
     30     # Stable, colon-free names for the two DRM cards. Aquamarine splits
     31     # AQ_DRM_DEVICES on ':', so the /dev/dri/by-path names cannot go in it (the PCI
     32     # address has colons): it chopped them into "pci-0000", "01", "00.0-card", found
     33     # no GPU and Hyprland aborted at startup with "CBackend::create() failed!".
     34     # ID_PATH is matched exactly so the boot-time simpledrm card (whose ID_PATH is
     35     # pci-0000:01:00.0-platform-simple-framebuffer.0) does not take the dGPU name.
     36     services.udev.extraRules = ''
     37       SUBSYSTEM=="drm", KERNEL=="card[0-9]*", ENV{ID_PATH}=="pci-0000:01:00.0", SYMLINK+="dri/dgpu-card"
     38       SUBSYSTEM=="drm", KERNEL=="card[0-9]*", ENV{ID_PATH}=="pci-0000:06:00.0", SYMLINK+="dri/igpu-card"
     39     '';
     40 
     41     environment.sessionVariables = {
     42       # Stable device order for Hyprland/aquamarine: dGPU (panel) first, iGPU second.
     43       AQ_DRM_DEVICES = "/dev/dri/dgpu-card:/dev/dri/igpu-card";
     44       LIBVA_DRIVER_NAME = "nvidia";
     45       __GLX_VENDOR_LIBRARY_NAME = "nvidia";
     46       NVD_BACKEND = "direct";
     47     };
     48 
     49     # Hybrid (iGPU drives the panel, dGPU on demand). Only if the BIOS MUX is set to hybrid:
     50     # hardware.nvidia.prime = {
     51     #   offload.enable = true;
     52     #   offload.enableOffloadCmd = true;
     53     #   amdgpuBusId = "PCI:6:0:0";
     54     #   nvidiaBusId = "PCI:1:0:0";
     55     # };
     56   }
     57   ;
     58 }