Skip to content

Commit

Permalink
quine: nvidia
Browse files Browse the repository at this point in the history
  • Loading branch information
Ramblurr committed Feb 3, 2025
1 parent a4de7c4 commit b8efe37
Show file tree
Hide file tree
Showing 5 changed files with 197 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .envrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
use flake
use nix
12 changes: 11 additions & 1 deletion hosts/quine/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,17 @@ in
networking.default.enable = true;
networking.default.hostName = hn;
hardware.ryzen.enable = true;
hardware.nvidia.enable = true;
hardware.easyNvidia = {
enable = true;
withIntegratedGPU = false;
vaapi = {
enable = true;
firefox = {
enable = true;
av1Support = true;
};
};
};
hardware.pipewire.enable = true;
hardware.pipewire.denoise.enable = true;
users.enable = true;
Expand Down
3 changes: 2 additions & 1 deletion modules-unstable/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

{
imports = [
./hardware/nvidia.nix
#./hardware/nvidia.nix
./hardware/nvidia
./services/microsocks.nix
];
}
89 changes: 89 additions & 0 deletions modules-unstable/hardware/nvidia/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# This is from Tristan Maat @TLATER
# source: https://github.com/TLATER/dotfiles/tree/32489827a2a85ac2d6584e84a11a0da37bdc19dc/nixos-modules/nvidia
{
pkgs,
config,
lib,
...
}:
let
cfg = config.modules.hardware.easyNvidia;
in
{
imports = [ ./vaapi.nix ];

options.modules.hardware.easyNvidia = with lib.types; {
enable = lib.mkEnableOption "easyNvidia";
withIntegratedGPU = lib.mkOption {
type = bool;
description = ''
Whether the computer has a separate integrated GPU.
This also configures the machine to use the integrated GPU for
other things like software decoding, so keep this enabled even
if you separately disable offload rendering.
'';
};
};

config = lib.mkIf cfg.enable {
services.xserver.videoDrivers = [ "nvidia" ];

hardware.nvidia = {
package = config.boot.kernelPackages.nvidiaPackages.mkDriver {
version = "565.77";
sha256_64bit = "sha256-CnqnQsRrzzTXZpgkAtF7PbH9s7wbiTRNcM0SPByzFHw=";
sha256_aarch64 = lib.fakeHash;
openSha256 = "sha256-Fxo0t61KQDs71YA8u7arY+503wkAc1foaa51vi2Pl5I=";
settingsSha256 = "sha256-VUetj3LlOSz/LB+DDfMCN34uA4bNTTpjDrb6C6Iwukk=";
persistencedSha256 = lib.fakeHash;
};

# This will no longer be necessary when
# https://github.com/NixOS/nixpkgs/pull/326369 hits stable
modesetting.enable = lib.mkDefault true;
# Power management is nearly always required to get nvidia GPUs to
# behave on suspend, due to firmware bugs.
powerManagement.enable = true;
# The open driver is recommended by nvidia now, see
# https://download.nvidia.com/XFree86/Linux-x86_64/565.57.01/README/kernel_open.html
open = true;

dynamicBoost.enable = cfg.enable && cfg.withIntegratedGPU;
};

boot = {
kernelPackages = lib.mkForce pkgs.linuxKernel.packages.linux_xanmod;

extraModprobeConfig =
"options nvidia "
+ lib.concatStringsSep " " [
# nvidia assume that by default your CPU does not support PAT,
# but this is effectively never the case in 2023
"NVreg_UsePageAttributeTable=1"
# This is sometimes needed for ddc/ci support, see
# https://www.ddcutil.com/nvidia/
#
# Current monitor does not support it, but this is useful for
# the future
"NVreg_RegistryDwords=RMUseSwI2c=0x01;RMI2cSpeed=100"
];
};

environment.variables = {
# Required to run the correct GBM backend for nvidia GPUs on wayland
GBM_BACKEND = "nvidia-drm";
# Apparently, without this nouveau may attempt to be used instead
# (despite it being blacklisted)
__GLX_VENDOR_LIBRARY_NAME = "nvidia";
# Hardware cursors are currently broken on wlroots
WLR_NO_HARDWARE_CURSORS = "1";
};
environment.systemPackages = [
pkgs.nvitop
pkgs.nvtopPackages.nvidia
pkgs.libva-utils
pkgs.cudaPackages.cudatoolkit
];
};
}
94 changes: 94 additions & 0 deletions modules-unstable/hardware/nvidia/vaapi.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
{
pkgs,
config,
lib,
...
}:
let
cfg = config.modules.hardware.easyNvidia.vaapi;
in
{
options.modules.hardware.easyNvidia.vaapi = with lib.types; {
enable = lib.mkOption {
type = bool;
default =
config.modules.hardware.easyNvidia.enable && !config.modules.hardware.easyNvidia.withIntegratedGPU;
description = ''
Whether to enable the NVIDIA vaapi driver.
This allows using the NVIDIA GPU for decoding video streams
instead of using software decoding on the CPU.
This particularly makes sense for desktop computers without an
iGPU, as on those software en/decoding will take a lot of
processing power while the NVIDIA GPU's encoding capacity
isn't doing anything, so this option is enabled by default
there.
However, on machines with an iGPU, the dGPU's en/decoding
capabilities are often more limited than those of the iGPU,
and require more power, so this is disabled there by default -
it may still make sense from time to time, so feel free to
experiment.
'';

};

maxInstances = lib.mkOption {
type = nullOr int;
default = null;
description = ''
The maximum number of concurrent instances of the driver.
Sometimes useful for graphics cards with little VRAM.
'';
};

firefox = {
enable = lib.mkOption {
type = bool;
default = config.programs.firefox.enable;
description = ''
Configure Firefox to used the vaapi driver for video decoding.
Note that this requires disabling the [RDD
sandbox](https://firefox-source-docs.mozilla.org/dom/ipc/process_model.html#data-decoder-rdd-process).
'';
};

av1Support = lib.mkOption {
type = bool;
default = false;
description = ''
Whether to enable av1 support.
This will not work on Turing (e.g. Geforce 2xxx) and
earlier, and is therefore disabled by default there.
'';
};
};
};

# See https://github.com/elFarto/nvidia-vaapi-driver#configuration
config = lib.mkIf cfg.enable {
environment = {
systemPackages = [ pkgs.libva-utils ];
variables =
{
NVD_BACKEND = "direct";
LIBVA_DRIVER_NAME = "nvidia";
}
// lib.optionalAttrs (cfg.maxInstances != null) { NVD_MAX_INSTANCES = toString cfg.maxInstances; }
// lib.optionalAttrs cfg.firefox.enable { MOZ_DISABLE_RDD_SANDBOX = "1"; };
};

programs.firefox.preferences = lib.mkIf cfg.firefox.enable {
"media.ffmpeg.vaapi.enabled" = true;
"media.rdd-ffmpeg.enabled" = true;
"media.av1.enabled" = cfg.firefox.av1Support;
"gfx.x11-egl.force-enabled" = true;
"widget.dmabuf.force-enabled" = true;
};
};
}

0 comments on commit b8efe37

Please sign in to comment.