Skip to content

Commit 5425988

Browse files
nvidia: generalize the setup
Setting up nvidia graphics. Signed-off-by: Brian McGillion <bmg.avoin@gmail.com>
1 parent 1e6d6ed commit 5425988

File tree

14 files changed

+271
-55
lines changed

14 files changed

+271
-55
lines changed

docs/src/release_notes/ghaf-25.03.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,4 @@ There are no specific requirements for the environment with this release.
100100

101101
Released images are available at [ghafreleasesstorage.z16.web.core.windows.net/ghaf-25-03](https://ghafreleasesstorage.z16.web.core.windows.net/ghaf-25-03).
102102

103-
Download the required image and use the following instructions: [Build and Run](../ref_impl/build_and_run.md).
103+
Download the required image and use the following instructions: [Build and Run](../ref_impl/build_and_run.md).

docs/src/release_notes/release_notes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ Release numbering scheme: *ghaf-yy.mm*.
2828
- [Release ghaf-23.12](../release_notes/ghaf-23.12.md)
2929
- [Release ghaf-23.09](../release_notes/ghaf-23.09.md)
3030
- [Release ghaf-23.06](../release_notes/ghaf-23.06.md)
31-
- [Release ghaf-23.05](../release_notes/ghaf-23.05.md)
31+
- [Release ghaf-23.05](../release_notes/ghaf-23.05.md)

modules/desktop/default.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66
{
77
imports = [
88
./graphics
9+
./nvidia-gpu
910
];
1011
}
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
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;
14+
in
15+
{
16+
imports = [
17+
./prime.nix
18+
./vaapi.nix
19+
];
20+
21+
options.ghaf.graphics.nvidia-setup = {
22+
enable = lib.mkEnableOption "Enable Nvidia setup";
23+
withIntegratedGPU = lib.mkOption {
24+
type = lib.types.bool;
25+
default = false;
26+
description = ''
27+
Whether the computer has a separate integrated GPU.
28+
29+
This also configures the machine to use the integrated GPU for
30+
other things like software decoding, so keep this enabled even
31+
if you separately disable offload rendering.
32+
'';
33+
};
34+
};
35+
36+
config = lib.mkIf cfg.enable {
37+
38+
hardware = {
39+
graphics.extraPackages = [
40+
pkgs.egl-wayland
41+
pkgs.mesa
42+
pkgs.libGL
43+
];
44+
45+
nvidia = {
46+
modesetting.enable = lib.mkDefault true;
47+
48+
gsp.enable = true;
49+
50+
# TODO: test enabling these to resume from sleep/suspend states
51+
powerManagement.enable = false;
52+
# TODO: this may fix screen tearing but if not needed it can cause more issues
53+
# than it actually fixes. so leave it to off by default
54+
#forceFullCompositionPipeline = true;
55+
# TODO: testing the open drivers recommended by nvidia
56+
open = true; # false;
57+
nvidiaSettings = true;
58+
package = config.boot.kernelPackages.nvidiaPackages.beta; # was beta
59+
60+
dynamicBoost.enable = cfg.enable && cfg.withIntegratedGPU;
61+
};
62+
};
63+
64+
# Load nvidia driver for Xorg and Wayland
65+
services.xserver.videoDrivers = [ "nvidia" ];
66+
67+
boot = {
68+
# TODO: what exactly does xanmod package bring?
69+
# https://xanmod.org/
70+
# many things like clear linux and supposed better nvidia support?
71+
# https://pq.hosting/en/help/modificirovannoe-jadro-xanmod
72+
# TODO; seems legit and migth be worth it
73+
#kernelPackages = lib.mkForce pkgs.linuxKernel.packages.linux_xanmod;
74+
75+
extraModprobeConfig =
76+
"options nvidia "
77+
+ lib.concatStringsSep " " [
78+
# nvidia assume that by default your CPU does not support PAT,
79+
# but this is effectively never the case in 2023
80+
"NVreg_UsePageAttributeTable=1"
81+
# This is sometimes needed for ddc/ci support, see
82+
# https://www.ddcutil.com/nvidia/
83+
#
84+
# Current monitor does not support it, but this is useful for
85+
# the future
86+
"NVreg_RegistryDwords=RMUseSwI2c=0x01;RMI2cSpeed=100"
87+
];
88+
};
89+
90+
environment.variables = {
91+
# Required to run the correct GBM backend for nvidia GPUs on wayland
92+
GBM_BACKEND = "nvidia-drm";
93+
# Apparently, without this nouveau may attempt to be used instead
94+
# (despite it being blacklisted)
95+
__GLX_VENDOR_LIBRARY_NAME = "nvidia";
96+
# Hardware cursors are currently broken on wlroots
97+
# TODO: is this still the case? seems that nixos defaults to 0
98+
WLR_NO_HARDWARE_CURSORS = lib.mkForce "1";
99+
};
100+
};
101+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Copyright 2025 TII (SSRC) and the Ghaf contributors
2+
# Copyright TLATER
3+
#
4+
# SPDX-License-Identifier: Apache-2.0
5+
# from https://github.com/TLATER/dotfiles
6+
{
7+
config,
8+
lib,
9+
...
10+
}:
11+
let
12+
cfg = config.ghaf.graphics.nvidia-setup.prime;
13+
in
14+
{
15+
options.ghaf.graphics.nvidia-setup.prime = {
16+
enable = lib.mkOption {
17+
type = lib.types.bool;
18+
default =
19+
config.ghaf.graphics.nvidia-setup.enable && config.ghaf.graphics.nvidia-setup.withIntegratedGPU;
20+
description = ''
21+
Whether to configure prime offload.
22+
23+
This will allow on-demand offloading of rendering tasks to the
24+
NVIDIA GPU, all other rendering will happen on the GPU
25+
integrated in the CPU.
26+
27+
The GPU *should* be turned off whenever it is not in use, so
28+
this shouldn't cause increased battery drain, but there are
29+
some reports floating around that this isn't always the case -
30+
likely especially for older devices. Feel free to turn it off
31+
if you find this doesn't work properly for you.
32+
33+
'';
34+
};
35+
};
36+
37+
config = lib.mkIf cfg.enable {
38+
hardware.nvidia = {
39+
prime.offload = {
40+
enable = true;
41+
enableOffloadCmd = true;
42+
};
43+
44+
powerManagement.finegrained = true;
45+
};
46+
};
47+
}
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
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+
}

modules/hardware/x86_64-generic/x86_64-linux.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ in
3636
systemd-boot.enable = true;
3737
};
3838

39-
kernelPackages = pkgs.linuxPackages_latest;
39+
kernelPackages = pkgs.linuxPackages;
4040
};
4141
};
4242
}

modules/microvm/sysvms/guivm.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ in
339339
if config.ghaf.guest.kernel.hardening.graphics.enable then
340340
pkgs.linuxPackagesFor guest_graphics_hardened_kernel
341341
else
342-
pkgs.linuxPackages_latest;
342+
pkgs.linuxPackages;
343343

344344
# We need this patch to avoid reserving Intel graphics stolen memory for vm
345345
# https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/12103

modules/reference/hardware/alienware/extra-config.nix

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,20 @@
22
# SPDX-License-Identifier: Apache-2.0
33
{
44
pkgs,
5-
lib,
65
...
76
}:
87
{
9-
hardware = {
10-
graphics.extraPackages = [
11-
pkgs.egl-wayland
12-
pkgs.mesa
13-
pkgs.libGL
14-
];
15-
nvidia = {
16-
modesetting.enable = true;
17-
powerManagement.enable = false;
18-
powerManagement.finegrained = false;
19-
forceFullCompositionPipeline = true;
20-
open = false;
21-
nvidiaSettings = false;
22-
prime = {
23-
intelBusId = "PCI:0:11:0";
24-
nvidiaBusId = "PCI:0:12:0";
25-
offload.enable = lib.mkForce true;
26-
offload.enableOffloadCmd = lib.mkForce true;
27-
};
28-
};
8+
ghaf.graphics.nvidia-setup = {
9+
enable = true;
10+
withIntegratedGPU = true;
2911
};
3012

31-
# Load nvidia driver for Xorg and Wayland
32-
services.xserver.videoDrivers = [ "nvidia" ];
13+
hardware.nvidia = {
14+
prime = {
15+
intelBusId = "PCI:0:11:0";
16+
nvidiaBusId = "PCI:0:12:0";
17+
};
18+
};
3319

3420
microvm.qemu.extraArgs = [
3521
"-drive"

modules/reference/hardware/alienware/net-config.nix

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Copyright 2025 TII (SSRC) and the Ghaf contributors
22
# SPDX-License-Identifier: Apache-2.0
33
{
4-
config,
54
pkgs,
65
...
76
}:

0 commit comments

Comments
 (0)