diff --git a/common/gpu/nvidia.nix b/common/gpu/nvidia.nix new file mode 100644 index 0000000..fed9fa9 --- /dev/null +++ b/common/gpu/nvidia.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 -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 + }; +} diff --git a/dell/xps/15-9500/README.wiki b/dell/xps/15-9500/README.wiki index d2e0456..ebcb5e3 100644 --- a/dell/xps/15-9500/README.wiki +++ b/dell/xps/15-9500/README.wiki @@ -12,3 +12,11 @@ == Notes == 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. diff --git a/dell/xps/15-9500/nvidia/default.nix b/dell/xps/15-9500/nvidia/default.nix index b7150c1..75d5d73 100644 --- a/dell/xps/15-9500/nvidia/default.nix +++ b/dell/xps/15-9500/nvidia/default.nix @@ -1,27 +1,11 @@ { 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 = [ ../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 = { - offload.enable = lib.mkDefault true; - # Bus ID of the Intel GPU. intelBusId = lib.mkDefault "PCI:0:2:0"; diff --git a/dell/xps/15-9500/xps-common.nix b/dell/xps/15-9500/xps-common.nix index afa627d..7cec13c 100644 --- a/dell/xps/15-9500/xps-common.nix +++ b/dell/xps/15-9500/xps-common.nix @@ -15,10 +15,10 @@ in # This will save you money and possibly your life! 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; - # 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"; - }