From 280c9c69d05af4912f2274ff83af63433b2b25f4 Mon Sep 17 00:00:00 2001 From: Peder Bergebakken Sundt Date: Sun, 18 Jun 2023 23:36:17 +0200 Subject: [PATCH] cuda --- flake.nix | 2 +- hardware/cuda.nix | 48 ++++++++++++++++++++++++++++++++++++++++++ hardware/rocm.nix | 1 + hosts/sopp/default.nix | 2 +- 4 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 hardware/cuda.nix diff --git a/flake.nix b/flake.nix index 8bba91b..10e043f 100644 --- a/flake.nix +++ b/flake.nix @@ -104,7 +104,7 @@ noximilien = mkConfig "noximilien" "x86_64-linux" (with nm; [ common-pc common-pc-ssd common-cpu-intel ]); bolle = mkConfig "bolle" "x86_64-linux" (with nm; [ common-pc common-pc-ssd common-cpu-intel ]); nord = mkConfig "nord" "x86_64-linux" (with nm; [ common-pc common-pc-ssd common-cpu-intel-cpu-only common-gpu-amd ]); - sopp = mkConfig "sopp" "x86_64-linux" (with nm; [ common-pc common-pc-ssd common-cpu-intel ]); # TODO: common-gpu-nvidia + sopp = mkConfig "sopp" "x86_64-linux" (with nm; [ common-pc common-pc-ssd common-cpu-intel-cpu-only common-gpu-nvidia-nonprime ]); }; homeConfigurations = forAllSystems (system: let diff --git a/hardware/cuda.nix b/hardware/cuda.nix new file mode 100644 index 0000000..281a40a --- /dev/null +++ b/hardware/cuda.nix @@ -0,0 +1,48 @@ +{ config, pkgs, lib, ... }: +{ + # assumes common-gpu-nvidia from nixos-hardware is also added + # TODO: should we move it from flake.nix to here? + + # https://nixos.wiki/wiki/Nvidia + + nixpkgs.config.cudaSupport = true; + nixpkgs.config.allowUnfreePredicate = pkg: lib.any (x: x) [ + (lib.hasInfix "nvidia" (lib.toLower (lib.getName pkg))) + (lib.hasInfix "cuda" (lib.toLower (lib.getName pkg))) + (lib.hasInfix "cudnn" (lib.toLower (lib.getName pkg))) + (lib.hasInfix "cublas" (lib.toLower (lib.getName pkg))) + ]; + + hardware.opengl.enable = true; + hardware.nvidia.package = config.boot.kernelPackages.nvidiaPackages.stable; + hardware.nvidia.modesetting.enable = true; + + # add this to the host in question: + #hardware.nvidia.prime = { + # offload.enable = true; + # # Bus IDs. You can find them using lspci, grepping for "3D" or "VGA" + # intelBusId = "PCI:0:2:0"; + # nvidiaBusId = "PCI:1:0:0"; + #}; + + environment.systemPackages = with pkgs; ([ + nvtop + + ] ++ lib.optional hardware.nvidia.prime.offload.enable [ + (writeShellScriptBin "prime-run" '' + 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 "$@" + '') + # already added by nixos-hardware.common-gpu-nvidia + #(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 "$@" + #'') + ]); +} diff --git a/hardware/rocm.nix b/hardware/rocm.nix index d5e523b..c24d805 100644 --- a/hardware/rocm.nix +++ b/hardware/rocm.nix @@ -5,6 +5,7 @@ # https://libreddit.noximilien.pbsds.net/r/archlinux/comments/nih9c9/amdgpu_vs_modesetting_in_current_510_kernels_xorg/ + hardware.opengl.enable = true; services.xserver.videoDrivers = [ "amdgpu" ]; # use gpu, adaptive sync and and hardware page flipping #services.xserver.videoDrivers = [ "modesetting" ]; # integrated (non-accelerated) framebuffer, KMS diff --git a/hosts/sopp/default.nix b/hosts/sopp/default.nix index 9f9410b..5aebe30 100644 --- a/hosts/sopp/default.nix +++ b/hosts/sopp/default.nix @@ -14,7 +14,7 @@ imports = [ ./hardware-configuration.nix - #../../hardware/rocm.nix # TODO: CUDA + ../../hardware/cuda.nix ../../hardware/opengl-intel.nix ../../users # home-manager