From 7e60458d8646f79a5df228913f87f59cc14414da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tristan=20Dani=C3=ABl=20Maat?= Date: Sun, 13 Nov 2022 01:32:01 +0000 Subject: [PATCH] common/gpu/nvidia*: Migrate to common/gpu/nvidia/* and add non-prime Fixes #338 --- common/gpu/nvidia-disable.nix | 14 ++++++++------ common/gpu/nvidia.nix | 28 +++++++--------------------- common/gpu/nvidia/default.nix | 8 ++++++++ common/gpu/nvidia/disable.nix | 9 +++++++++ common/gpu/nvidia/prime.nix | 22 ++++++++++++++++++++++ flake.nix | 5 +++-- 6 files changed, 57 insertions(+), 29 deletions(-) create mode 100644 common/gpu/nvidia/default.nix create mode 100644 common/gpu/nvidia/disable.nix create mode 100644 common/gpu/nvidia/prime.nix diff --git a/common/gpu/nvidia-disable.nix b/common/gpu/nvidia-disable.nix index c6516af..3f28c4e 100644 --- a/common/gpu/nvidia-disable.nix +++ b/common/gpu/nvidia-disable.nix @@ -1,9 +1,11 @@ -{ lib, pkgs, ... }: - { - # This runs only intel/amdgpu igpus and nvidia dgpus do not drain power. + imports = [ ./nvidia/disable.nix ]; - ##### disable nvidia, very nice battery life. - hardware.nvidiaOptimus.disable = lib.mkDefault true; - boot.blacklistedKernelModules = lib.mkDefault [ "nouveau" "nvidia" ]; + warnings = [ + '' + DEPRECATED: The module has been deprecated. + + Switch to using instead. + '' + ]; } diff --git a/common/gpu/nvidia.nix b/common/gpu/nvidia.nix index dffeb2a..9443b06 100644 --- a/common/gpu/nvidia.nix +++ b/common/gpu/nvidia.nix @@ -1,26 +1,12 @@ -{ lib, pkgs, ... }: - -# This creates a new 'nvidia-offload' program that runs the application passed to it on the GPU -# As per https://nixos.wiki/wiki/Nvidia -let - nvidia-offload = pkgs.writeShellScriptBin "nvidia-offload" '' - export __NV_PRIME_RENDER_OFFLOAD=1 - export __NV_PRIME_RENDER_OFFLOAD_PROVIDER=NVIDIA-G0 - export __GLX_VENDOR_LIBRARY_NAME=nvidia - export __VK_LAYER_NV_optimus=NVIDIA_only - exec "$@" - ''; -in { - services.xserver.videoDrivers = lib.mkDefault [ "nvidia" ]; - environment.systemPackages = [ nvidia-offload ]; + imports = [ ./nvidia/prime.nix ]; - hardware.nvidia.prime = { - offload.enable = lib.mkDefault true; - # Hardware should specify the bus ID for intel/nvidia devices - }; + warnings = [ + '' + DEPRECATED: The module has been deprecated. - hardware.opengl.extraPackages = with pkgs; [ - vaapiVdpau + Switch to using instead if you use prime offloading. + If you are using this without prime, consider switching to instead. + '' ]; } diff --git a/common/gpu/nvidia/default.nix b/common/gpu/nvidia/default.nix new file mode 100644 index 0000000..47f2d34 --- /dev/null +++ b/common/gpu/nvidia/default.nix @@ -0,0 +1,8 @@ +{ lib, pkgs, ... }: + +{ + services.xserver.videoDrivers = lib.mkDefault [ "nvidia" ]; + hardware.opengl.extraPackages = with pkgs; [ + vaapiVdpau + ]; +} diff --git a/common/gpu/nvidia/disable.nix b/common/gpu/nvidia/disable.nix new file mode 100644 index 0000000..c6516af --- /dev/null +++ b/common/gpu/nvidia/disable.nix @@ -0,0 +1,9 @@ +{ lib, pkgs, ... }: + +{ + # This runs only intel/amdgpu igpus and nvidia dgpus do not drain power. + + ##### disable nvidia, very nice battery life. + hardware.nvidiaOptimus.disable = lib.mkDefault true; + boot.blacklistedKernelModules = lib.mkDefault [ "nouveau" "nvidia" ]; +} diff --git a/common/gpu/nvidia/prime.nix b/common/gpu/nvidia/prime.nix new file mode 100644 index 0000000..79cf9fd --- /dev/null +++ b/common/gpu/nvidia/prime.nix @@ -0,0 +1,22 @@ +{ lib, pkgs, ... }: + +# This creates a new 'nvidia-offload' program that runs the application passed to it on the GPU +# As per https://nixos.wiki/wiki/Nvidia +let + nvidia-offload = pkgs.writeShellScriptBin "nvidia-offload" '' + export __NV_PRIME_RENDER_OFFLOAD=1 + export __NV_PRIME_RENDER_OFFLOAD_PROVIDER=NVIDIA-G0 + export __GLX_VENDOR_LIBRARY_NAME=nvidia + export __VK_LAYER_NV_optimus=NVIDIA_only + exec "$@" + ''; +in { + imports = [ ./. ]; + + environment.systemPackages = [ nvidia-offload ]; + + hardware.nvidia.prime = { + offload.enable = lib.mkDefault true; + # Hardware should specify the bus ID for intel/nvidia devices + }; +} diff --git a/flake.nix b/flake.nix index 238d2d7..c18d993 100644 --- a/flake.nix +++ b/flake.nix @@ -157,8 +157,9 @@ common-gpu-amd-sea-islands = import ./common/gpu/amd/sea-islands; common-gpu-amd-southern-islands = import ./common/gpu/amd/southern-islands; common-gpu-intel = import ./common/gpu/intel.nix; - common-gpu-nvidia = import ./common/gpu/nvidia.nix; - common-gpu-nvidia-disable = import ./common/gpu/nvidia-disable.nix; + common-gpu-nvidia = import ./common/gpu/nvidia/prime.nix; + common-gpu-nvidia-nonprime = import ./common/gpu/nvidia; + common-gpu-nvidia-disable = import ./common/gpu/nvidia/disable.nix; common-pc = import ./common/pc; common-pc-hdd = import ./common/pc/hdd; common-pc-laptop = import ./common/pc/laptop;