repositories

NixDaemon

NixOS pentest workstation as one flake — IceBreaker's successor

clonegit clone https://git.daemon-sec.xyz/NixDaemon.git
nvidia.nixNix58 lines2.4 KiBraw download
# modules/hosts/laptop/nvidia.nix
#
# The panel (eDP-1) is wired to the RTX 3070 Ti at 01:00.0: the firmware MUX is
# in discrete mode (amdgpu's eDP-2 reports disconnected). Linux cannot change
# the MUX, so this configures what the hardware presents: NVIDIA open kernel
# module with modesetting, the Radeon 680M left as a secondary DRM device.
#
# PARKED: if the MUX is switched to hybrid in the BIOS, swap the AQ_DRM_DEVICES
# order (igpu-card first) and add the prime offload block at the bottom.
{ ... }:
{
  flake.nixosModules.laptop-nvidia =
  { config, pkgs, lib, ... }:
  {
    services.xserver.videoDrivers = [ "nvidia" ];

    hardware.graphics = {
      enable = true;
      extraPackages = [ pkgs.nvidia-vaapi-driver ];
    };

    hardware.nvidia = {
      open = true; # GA104 is supported by the open kernel modules
      modesetting.enable = true; # nvidia-drm.modeset=1
      package = config.boot.kernelPackages.nvidiaPackages.stable;
      nvidiaSettings = false;
      # powerManagement.enable = true;  # suspend/resume helpers; untested on this laptop, left at default
    };

    # Stable, colon-free names for the two DRM cards. Aquamarine splits
    # AQ_DRM_DEVICES on ':', so the /dev/dri/by-path names cannot go in it (the PCI
    # address has colons): it chopped them into "pci-0000", "01", "00.0-card", found
    # no GPU and Hyprland aborted at startup with "CBackend::create() failed!".
    # ID_PATH is matched exactly so the boot-time simpledrm card (whose ID_PATH is
    # pci-0000:01:00.0-platform-simple-framebuffer.0) does not take the dGPU name.
    services.udev.extraRules = ''
      SUBSYSTEM=="drm", KERNEL=="card[0-9]*", ENV{ID_PATH}=="pci-0000:01:00.0", SYMLINK+="dri/dgpu-card"
      SUBSYSTEM=="drm", KERNEL=="card[0-9]*", ENV{ID_PATH}=="pci-0000:06:00.0", SYMLINK+="dri/igpu-card"
    '';

    environment.sessionVariables = {
      # Stable device order for Hyprland/aquamarine: dGPU (panel) first, iGPU second.
      AQ_DRM_DEVICES = "/dev/dri/dgpu-card:/dev/dri/igpu-card";
      LIBVA_DRIVER_NAME = "nvidia";
      __GLX_VENDOR_LIBRARY_NAME = "nvidia";
      NVD_BACKEND = "direct";
    };

    # Hybrid (iGPU drives the panel, dGPU on demand). Only if the BIOS MUX is set to hybrid:
    # hardware.nvidia.prime = {
    #   offload.enable = true;
    #   offload.enableOffloadCmd = true;
    #   amdgpuBusId = "PCI:6:0:0";
    #   nvidiaBusId = "PCI:1:0:0";
    # };
  }
  ;
}