From 618cd6de8dc0245868fafe14dfecd12695e4ed23 Mon Sep 17 00:00:00 2001 From: Christopher James Hayward Date: Thu, 17 Jun 2021 11:44:16 -0400 Subject: [PATCH] Add nvidia module --- README.org | 40 ++++++++++++++++++++++++++++++++++++++++ flake.nix | 1 + modules/nvidia.nix | 29 +++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+) create mode 100644 modules/nvidia.nix diff --git a/README.org b/README.org index a66c5d2..26b2f6c 100644 --- a/README.org +++ b/README.org @@ -467,6 +467,7 @@ acernitro = nixpkgs.lib.nixosSystem { <> <> <> + <> <> <> <> @@ -856,6 +857,45 @@ Docker [fn:29] is a set of platform as a service that uses OS level virtualizati } #+END_SRC +** NVIDIA + +#+NAME: module-nvidia +#+BEGIN_SRC nix +./modules/nvidia.nix +#+END_SRC + +#+BEGIN_SRC nix :noweb yes :tangle modules/nvidia.nix +{ config, pkgs, ... }: + +let + myIntelBusId = "PCI:0:2:0"; + myNvidiaBusId = "PCI:1:0:0"; + myNvidiaOffload = 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 { + # Add the offload script to the $PATH. + environment.systemPackages = [ myNvidiaOffload ]; + + # Enable the NVIDIA drivers. + # NOTE: You may need to use either of the commands below: + services.xserver.videoDrivers = [ "nvidia" ]; + # services.xserver.videoDrivers = [ "modesetting" "nvidia" ]; + + # Configure `offload-mode'. + hardware.nvidia.prime = { + offload.enable = true; + intelBusId = myIntelBusId; + nvidiaBusId = myNvidiaBusId; + }; +} +#+END_SRC + ** Firefox #+NAME: module-firefox diff --git a/flake.nix b/flake.nix index 7b8e22a..19f5ef0 100644 --- a/flake.nix +++ b/flake.nix @@ -46,6 +46,7 @@ ./modules/x11.nix ./modules/flakes.nix ./modules/cachix.nix + ./modules/nvidia.nix ./modules/firefox.nix ./modules/moonlight.nix ./modules/teamviewer.nix diff --git a/modules/nvidia.nix b/modules/nvidia.nix new file mode 100644 index 0000000..9f89ebc --- /dev/null +++ b/modules/nvidia.nix @@ -0,0 +1,29 @@ +{ config, pkgs, ... }: + +let + myIntelBusId = "PCI:0:2:0"; + myNvidiaBusId = "PCI:1:0:0"; + myNvidiaOffload = 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 { + # Add the offload script to the $PATH. + environment.systemPackages = [ myNvidiaOffload ]; + + # Enable the NVIDIA drivers. + # NOTE: You may need to use either of the commands below: + services.xserver.videoDrivers = [ "nvidia" ]; + # services.xserver.videoDrivers = [ "modesetting" "nvidia" ]; + + # Configure `offload-mode'. + hardware.nvidia.prime = { + offload.enable = true; + intelBusId = myIntelBusId; + nvidiaBusId = myNvidiaBusId; + }; +}