Files
nix-config/hosts/idols-ai/nvidia.nix
2026-02-15 22:53:44 +08:00

78 lines
2.5 KiB
Nix

{
config,
lib,
pkgs,
...
}:
{
# ===============================================================================================
# for Nvidia GPU
# https://wiki.nixos.org/wiki/NVIDIA
# https://wiki.hyprland.org/Nvidia/
# ===============================================================================================
boot.kernelParams = [
# Since NVIDIA does not load kernel mode setting by default,
# enabling it is required to make Wayland compositors function properly.
"nvidia-drm.fbdev=1"
];
services.xserver.videoDrivers = [ "nvidia" ]; # will install nvidia-vaapi-driver by default
hardware.nvidia = {
# Open-source kernel modules are preferred over and planned to steadily replace proprietary modules
open = true;
nvidiaSettings = true;
# Optionally, you may need to select the appropriate driver version for your specific GPU.
# https://github.com/NixOS/nixpkgs/blob/nixos-unstable/pkgs/os-specific/linux/nvidia-x11/default.nix
# package = config.boot.kernelPackages.nvidiaPackages.production;
# https://github.com/NixOS/nixpkgs/issues/489947
# Apply CachyOS kernel 6.19 patch to NVIDIA latest driver
package =
let
base = config.boot.kernelPackages.nvidiaPackages.latest;
cachyos-nvidia-patch = pkgs.fetchpatch {
url = "https://raw.githubusercontent.com/CachyOS/CachyOS-PKGBUILDS/master/nvidia/nvidia-utils/kernel-6.19.patch";
sha256 = "sha256-YuJjSUXE6jYSuZySYGnWSNG5sfVei7vvxDcHx3K+IN4=";
};
# Patch the appropriate driver based on config.hardware.nvidia.open
driverAttr = if config.hardware.nvidia.open then "open" else "bin";
in
base
// {
${driverAttr} = base.${driverAttr}.overrideAttrs (oldAttrs: {
patches = (oldAttrs.patches or [ ]) ++ [ cachyos-nvidia-patch ];
});
};
# required by most wayland compositors!
modesetting.enable = true;
powerManagement.enable = true;
dynamicBoost.enable = lib.mkForce true;
};
hardware.nvidia-container-toolkit.enable = true;
hardware.graphics = {
enable = true;
# needed by nvidia-docker
enable32Bit = true;
};
nixpkgs.overlays = [
(_: super: {
# ffmpeg-full = super.ffmpeg-full.override {
# withNvcodec = true;
# };
})
];
services.sunshine.settings = {
max_bitrate = 20000; # in Kbps
# NVIDIA NVENC Encoder
nvenc_preset = 3; # 1(fastest + worst quality) - 7(slowest + best quality)
nvenc_twopass = "full_res"; # quarter_res / full_res.
};
}