|
| 1 | +# Copyright 2025 TII (SSRC) and the Ghaf contributors |
| 2 | +# Copyright TLATER |
| 3 | +# |
| 4 | +# SPDX-License-Identifier: Apache-2.0 |
| 5 | +# derived from https://github.com/TLATER/dotfiles |
| 6 | +{ |
| 7 | + pkgs, |
| 8 | + config, |
| 9 | + lib, |
| 10 | + ... |
| 11 | +}: |
| 12 | +let |
| 13 | + cfg = config.ghaf.graphics.nvidia-setup.vaapi; |
| 14 | +in |
| 15 | +{ |
| 16 | + options.ghaf.graphics.nvidia-setup.vaapi = { |
| 17 | + enable = lib.mkOption { |
| 18 | + type = lib.types.bool; |
| 19 | + default = |
| 20 | + config.ghaf.graphics.nvidia-setup.enable && !config.ghaf.graphics.nvidia-setup.withIntegratedGPU; |
| 21 | + description = '' |
| 22 | + Whether to enable the NVIDIA vaapi driver. |
| 23 | +
|
| 24 | + This allows using the NVIDIA GPU for decoding video streams |
| 25 | + instead of using software decoding on the CPU. |
| 26 | +
|
| 27 | + This particularly makes sense for desktop computers without an |
| 28 | + iGPU, as on those software en/decoding will take a lot of |
| 29 | + processing power while the NVIDIA GPU's encoding capacity |
| 30 | + isn't doing anything, so this option is enabled by default |
| 31 | + there. |
| 32 | +
|
| 33 | + However, on machines with an iGPU, the dGPU's en/decoding |
| 34 | + capabilities are often more limited than those of the iGPU, |
| 35 | + and require more power, so this is disabled there by default - |
| 36 | + it may still make sense from time to time, so feel free to |
| 37 | + experiment. |
| 38 | +
|
| 39 | + ''; |
| 40 | + |
| 41 | + }; |
| 42 | + |
| 43 | + maxInstances = lib.mkOption { |
| 44 | + type = lib.types.nullOr lib.types.int; |
| 45 | + default = null; |
| 46 | + description = '' |
| 47 | + The maximum number of concurrent instances of the driver. |
| 48 | +
|
| 49 | + Sometimes useful for graphics cards with little VRAM. |
| 50 | + ''; |
| 51 | + }; |
| 52 | + |
| 53 | + # TODO: Add the same for the chrome browser |
| 54 | + firefox = { |
| 55 | + enable = lib.mkOption { |
| 56 | + type = lib.types.bool; |
| 57 | + default = config.programs.firefox.enable; |
| 58 | + description = '' |
| 59 | + Configure Firefox to used the vaapi driver for video decoding. |
| 60 | +
|
| 61 | + Note that this requires disabling the [RDD |
| 62 | + sandbox](https://firefox-source-docs.mozilla.org/dom/ipc/process_model.html#data-decoder-rdd-process). |
| 63 | + ''; |
| 64 | + }; |
| 65 | + |
| 66 | + av1Support = lib.mkOption { |
| 67 | + type = lib.types.bool; |
| 68 | + default = false; |
| 69 | + description = '' |
| 70 | + Whether to enable av1 support. |
| 71 | +
|
| 72 | + This will not work on Turing (e.g. Geforce 2xxx) and |
| 73 | + earlier, and is therefore disabled by default there. |
| 74 | + ''; |
| 75 | + }; |
| 76 | + }; |
| 77 | + }; |
| 78 | + |
| 79 | + # See https://github.com/elFarto/nvidia-vaapi-driver#configuration |
| 80 | + config = lib.mkIf cfg.enable { |
| 81 | + environment = { |
| 82 | + systemPackages = [ pkgs.libva-utils ]; |
| 83 | + variables = |
| 84 | + { |
| 85 | + NVD_BACKEND = "direct"; |
| 86 | + LIBVA_DRIVER_NAME = "nvidia"; |
| 87 | + } |
| 88 | + // lib.optionalAttrs (cfg.maxInstances != null) { NVD_MAX_INSTANCES = toString cfg.maxInstances; } |
| 89 | + // lib.optionalAttrs cfg.firefox.enable { MOZ_DISABLE_RDD_SANDBOX = "1"; }; |
| 90 | + }; |
| 91 | + |
| 92 | + hardware.graphics.extraPackages = [ |
| 93 | + pkgs.nvidia-vaapi-driver |
| 94 | + ]; |
| 95 | + |
| 96 | + programs.firefox.preferences = lib.mkIf cfg.firefox.enable { |
| 97 | + "media.ffmpeg.vaapi.enabled" = true; |
| 98 | + "media.rdd-ffmpeg.enabled" = true; |
| 99 | + "media.av1.enabled" = cfg.firefox.av1Support; |
| 100 | + "gfx.x11-egl.force-enabled" = true; |
| 101 | + "widget.dmabuf.force-enabled" = true; |
| 102 | + }; |
| 103 | + }; |
| 104 | +} |
0 commit comments