mirror of
https://github.com/aviallon/nixos-lib.git
synced 2026-04-06 01:38:06 +00:00
[Hardware/GPUs] Refactor GPU related options
[Hardware/NVidia] Add option to save all VRAM before going to sleep
This commit is contained in:
parent
09e949be39
commit
4d01393e59
8 changed files with 104 additions and 54 deletions
|
|
@ -5,14 +5,7 @@ let
|
||||||
desktopCfg = config.aviallon.desktop;
|
desktopCfg = config.aviallon.desktop;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
options.aviallon.hardware = {
|
options.aviallon.hardware = { };
|
||||||
gpuVendor = mkOption {
|
|
||||||
default = null;
|
|
||||||
example = "amd";
|
|
||||||
description = "Enable GPU vendor specific options";
|
|
||||||
type = types.enum [ "amd" "nvidia" "intel" ];
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
imports = [
|
imports = [
|
||||||
./hardware/amd.nix
|
./hardware/amd.nix
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,14 @@
|
||||||
{ config, pkgs, lib, ... }:
|
{ config, pkgs, lib, ... }:
|
||||||
with lib;
|
with lib;
|
||||||
let
|
let
|
||||||
hardwareCfg = config.aviallon.hardware;
|
cfg = config.aviallon.hardware.amd;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
config = mkIf (hardwareCfg.gpuVendor == "amd") {
|
options.aviallon.hardware.amd = {
|
||||||
|
enable = mkEnableOption "AMD gpus";
|
||||||
|
};
|
||||||
|
|
||||||
|
config = mkIf (cfg.enable) {
|
||||||
boot.initrd.kernelModules = [ "amdgpu" ];
|
boot.initrd.kernelModules = [ "amdgpu" ];
|
||||||
|
|
||||||
aviallon.boot.cmdline = {}
|
aviallon.boot.cmdline = {}
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,14 @@
|
||||||
{ config, pkgs, lib, ... }:
|
{ config, pkgs, lib, ... }:
|
||||||
with lib;
|
with lib;
|
||||||
let
|
let
|
||||||
hardwareCfg = config.aviallon.hardware;
|
cfg = config.aviallon.hardware.intel;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
config = mkIf (hardwareCfg.gpuVendor == "intel") {
|
options.aviallon.hardware.intel = {
|
||||||
|
enable = mkEnableOption "Intel GPUs";
|
||||||
|
};
|
||||||
|
|
||||||
|
config = mkIf cfg.enable {
|
||||||
boot.initrd.kernelModules = [ "i915" ];
|
boot.initrd.kernelModules = [ "i915" ];
|
||||||
hardware.opengl = {
|
hardware.opengl = {
|
||||||
enable = true;
|
enable = true;
|
||||||
|
|
|
||||||
|
|
@ -1,50 +1,20 @@
|
||||||
{ config, pkgs, lib, ... }:
|
{ config, pkgs, lib, ... }:
|
||||||
with lib;
|
with lib;
|
||||||
let
|
let
|
||||||
cfg = config.aviallon.hardware;
|
cfg = config.aviallon.hardware.nvidia;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
imports = [
|
imports = [
|
||||||
./nvidia
|
./nvidia
|
||||||
];
|
];
|
||||||
|
|
||||||
options.aviallon.hardware.useProprietary = mkEnableOption "nvidia proprietary drivers";
|
options.aviallon.hardware.nvidia = {
|
||||||
|
enable = mkEnableOption "enable Nvidia hardware config";
|
||||||
|
useProprietary = mkEnableOption "nvidia proprietary drivers";
|
||||||
|
saveAllVram = mkEnableOption "back up all VRAM in /tmp before going to sleep. May reduce artifacts after resuming";
|
||||||
|
};
|
||||||
|
|
||||||
config = mkIf (cfg.gpuVendor == "nvidia") {
|
config = mkIf cfg.enable {
|
||||||
boot.initrd.kernelModules = if cfg.useProprietary then [
|
|
||||||
"nvidia"
|
|
||||||
"nvidia_drm"
|
|
||||||
"nvidia_uvm"
|
|
||||||
"nvidia_modeset"
|
|
||||||
] else [ "nouveau" ];
|
|
||||||
# boot.blacklistedKernelModules = optional cfg.useProprietary "nouveau";
|
|
||||||
services.xserver.videoDrivers = optional cfg.useProprietary "nvidia";
|
|
||||||
hardware.opengl.driSupport32Bit = true;
|
hardware.opengl.driSupport32Bit = true;
|
||||||
hardware.nvidia = {
|
|
||||||
powerManagement.enable = true;
|
|
||||||
modesetting.enable = true;
|
|
||||||
};
|
|
||||||
|
|
||||||
aviallon.programs.allowUnfreeList = mkIf (cfg.useProprietary) [
|
|
||||||
"nvidia-x11"
|
|
||||||
"nvidia-settings"
|
|
||||||
];
|
|
||||||
|
|
||||||
hardware.opengl.extraPackages = with pkgs; [
|
|
||||||
libvdpau-va-gl
|
|
||||||
vaapiVdpau
|
|
||||||
];
|
|
||||||
|
|
||||||
hardware.opengl.extraPackages32 = with pkgs.pkgsi686Linux; [
|
|
||||||
libvdpau-va-gl
|
|
||||||
vaapiVdpau
|
|
||||||
];
|
|
||||||
|
|
||||||
# See documentation here: https://download.nvidia.com/XFree86/Linux-x86_64/510.60.02/README/openglenvvariables.html
|
|
||||||
environment.variables = ifEnable cfg.useProprietary {
|
|
||||||
"__GL_YIELD" = "USLEEP"; # use usleep(0) instead of sched_yield() -> better performance in most cases
|
|
||||||
"__GL_ALLOW_UNOFFICIAL_PROTOCOL" = "1"; # allow unofficial GLX protocol if also set in Xorg conf
|
|
||||||
"__GL_VRR_ALLOWED" = "1"; # Try to enable G-SYNC VRR if screen AND app is compatible
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,5 +2,7 @@
|
||||||
{
|
{
|
||||||
imports = [
|
imports = [
|
||||||
./vgpu.nix
|
./vgpu.nix
|
||||||
|
./proprietary.nix
|
||||||
|
./opensource.nix
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
9
hardware/nvidia/opensource.nix
Normal file
9
hardware/nvidia/opensource.nix
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
{ config, pkgs, lib, ... }:
|
||||||
|
with lib;
|
||||||
|
let
|
||||||
|
cfg = config.aviallon.hardware.nvidia;
|
||||||
|
in {
|
||||||
|
config = mkIf (cfg.enable && !cfg.useProprietary) {
|
||||||
|
boot.initrd.kernelModules = [ "nouveau" ];
|
||||||
|
};
|
||||||
|
}
|
||||||
62
hardware/nvidia/proprietary.nix
Normal file
62
hardware/nvidia/proprietary.nix
Normal file
|
|
@ -0,0 +1,62 @@
|
||||||
|
{ config, pkgs, lib, ... }:
|
||||||
|
with lib;
|
||||||
|
let
|
||||||
|
cfg = config.aviallon.hardware.nvidia;
|
||||||
|
in {
|
||||||
|
config = mkIf (cfg.enable && cfg.useProprietary) {
|
||||||
|
boot.initrd.kernelModules = [
|
||||||
|
"nvidia"
|
||||||
|
"nvidia_drm"
|
||||||
|
"nvidia_uvm"
|
||||||
|
"nvidia_modeset"
|
||||||
|
];
|
||||||
|
# boot.blacklistedKernelModules = [ "nouveau" ];
|
||||||
|
services.xserver.videoDrivers = [
|
||||||
|
"nvidia"
|
||||||
|
];
|
||||||
|
|
||||||
|
hardware.nvidia = {
|
||||||
|
powerManagement.enable = true;
|
||||||
|
powerManagement.finegrained = ifEnable config.hardware.nvidia.prime.offload.enable true;
|
||||||
|
modesetting.enable = true;
|
||||||
|
#package = with config.boot.kernelPackages.nvidiaPackages;
|
||||||
|
# if (cfg.driver == "stable") then
|
||||||
|
# stable
|
||||||
|
# else if (cfg.driver == "390") then
|
||||||
|
# legacy_390
|
||||||
|
# else if (cfg.driver == "340") then
|
||||||
|
# legacy_340
|
||||||
|
# else
|
||||||
|
# null
|
||||||
|
# ;
|
||||||
|
};
|
||||||
|
services.xserver.displayManager.gdm.nvidiaWayland = mkDefault true;
|
||||||
|
|
||||||
|
aviallon.boot.cmdline = mkIf cfg.saveAllVram {
|
||||||
|
NVreg_PreserveVideoMemoryAllocations = 1;
|
||||||
|
NVreg_TemporaryFilePath = "/tmp/nvidia-gpu.vram.img";
|
||||||
|
};
|
||||||
|
|
||||||
|
aviallon.programs.allowUnfreeList = [
|
||||||
|
"nvidia-x11"
|
||||||
|
"nvidia-settings"
|
||||||
|
];
|
||||||
|
|
||||||
|
hardware.opengl.extraPackages = with pkgs; [
|
||||||
|
libvdpau-va-gl
|
||||||
|
vaapiVdpau
|
||||||
|
];
|
||||||
|
|
||||||
|
hardware.opengl.extraPackages32 = with pkgs.pkgsi686Linux; [
|
||||||
|
libvdpau-va-gl
|
||||||
|
vaapiVdpau
|
||||||
|
];
|
||||||
|
|
||||||
|
# See documentation here: https://download.nvidia.com/XFree86/Linux-x86_64/510.60.02/README/openglenvvariables.html
|
||||||
|
environment.variables = {
|
||||||
|
"__GL_YIELD" = "USLEEP"; # use usleep(0) instead of sched_yield() -> better performance in most cases
|
||||||
|
"__GL_ALLOW_UNOFFICIAL_PROTOCOL" = "1"; # allow unofficial GLX protocol if also set in Xorg conf
|
||||||
|
"__GL_VRR_ALLOWED" = "1"; # Try to enable G-SYNC VRR if screen AND app is compatible
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
@ -1,15 +1,21 @@
|
||||||
{config, pkgs, lib, ...}:
|
{config, pkgs, lib, ...}:
|
||||||
with lib;
|
with lib;
|
||||||
let
|
let
|
||||||
cfg = config.aviallon.hardware;
|
cfg = config.aviallon.hardware.nvidia;
|
||||||
nixos-nvidia-vgpu = import (builtins.fetchTarball "https://github.com/danielfullmer/nixos-nvidia-vgpu/archive/master.tar.gz") {
|
vgpu-git = fetchGit {
|
||||||
|
url = "https://github.com/danielfullmer/nixos-nvidia-vgpu.git";
|
||||||
|
rev = "a4be77969dc2a8acbe3a4882ba5f0324cca138b6";
|
||||||
|
ref = "master";
|
||||||
|
};
|
||||||
|
nixos-nvidia-vgpu = import vgpu-git {
|
||||||
inherit config;
|
inherit config;
|
||||||
inherit pkgs;
|
inherit pkgs;
|
||||||
inherit lib;
|
inherit lib;
|
||||||
};
|
};
|
||||||
useVgpu = (cfg.useProprietary &&
|
useVgpu = (
|
||||||
(cfg.gpuVendor == "nvidia") &&
|
cfg.enable && cfg.useProprietary &&
|
||||||
(versionOlder config.boot.kernelPackages.kernel.version "5.10"));
|
(versionOlder config.boot.kernelPackages.kernel.version "5.10")
|
||||||
|
);
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
imports = [
|
imports = [
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue