Moved NVIDIA config to common, and updated README.

This commit is contained in:
bahaynes 2020-07-25 23:53:47 -04:00
parent 6ffcdbacc5
commit b7a5f1188f
No known key found for this signature in database
GPG key ID: BBD46B0B5D4DF951
4 changed files with 34 additions and 20 deletions

22
common/gpu/nvidia.nix Normal file
View file

@ -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 -a "$0" "$@"
'';
in
{
services.xserver.videoDrivers = lib.mkDefault [ "nvidia" ];
environment.systemPackages = [ nvidia-offload ];
hardware.nvidia.prime = {
offload.enable = lib.mkDefault true;
# Hardware should specify the bus ID for intel/nvidia devices
};
}

View file

@ -12,3 +12,11 @@
== Notes == == Notes ==
Also tested with Dell WD19TB Thunderbolt Dock. Also tested with Dell WD19TB Thunderbolt Dock.
== NVIDIA Offload ==
In order to run a program on the NVIDIA gpu, you can use the `nvidia-offload` function, for example:
```
nvidia-offload `nix-shell -p glxinfo --run 'glxgears'`
```
This is a short bash script that sets the proper environment variables and calls your command.

View file

@ -1,27 +1,11 @@
{ lib, pkgs, ... }: { lib, pkgs, ... }:
# This creates a new 'nvidia-offload' program that runs the application passed to it on the GPU
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 -a "$0" "$@"
'';
in
{ {
imports = [ imports = [
../xps-common.nix ../xps-common.nix
../../../../common/gpu/nvidia.nix
]; ];
# As per https://nixos.wiki/wiki/Nvidia
services.xserver.videoDrivers = lib.mkDefault [ "nvidia" ];
environment.systemPackages = [ nvidia-offload ];
hardware.nvidia.prime = { hardware.nvidia.prime = {
offload.enable = lib.mkDefault true;
# Bus ID of the Intel GPU. # Bus ID of the Intel GPU.
intelBusId = lib.mkDefault "PCI:0:2:0"; intelBusId = lib.mkDefault "PCI:0:2:0";

View file

@ -15,10 +15,10 @@ in
# This will save you money and possibly your life! # This will save you money and possibly your life!
services.thermald.enable = lib.mkDefault true; services.thermald.enable = lib.mkDefault true;
# Thermald doesn't have a default config for the 9500 yet, the one in this repo was generated with dptfxtract-static: # Thermald doesn't have a default config for the 9500 yet, the one in this repo
# was generated with dptfxtract-static (https://github.com/intel/dptfxtract)
services.thermald.configFile = lib.mkDefault thermald-conf; services.thermald.configFile = lib.mkDefault thermald-conf;
# Set the tlp config to powersave explictly (this should be default). TLP is enabled in common/pc/laptop. # Set the tlp config to powersave explictly. TLP is enabled in common/pc/laptop.
services.tlp.extraConfig = lib.mkDefault "CPU_SCALING_GOVERNOR_ON_AC=powersave\nCPU_SCALING_GOVERNOR_ON_BAT=powersave"; services.tlp.extraConfig = lib.mkDefault "CPU_SCALING_GOVERNOR_ON_AC=powersave\nCPU_SCALING_GOVERNOR_ON_BAT=powersave";
} }