Skip to content

Commit

Permalink
feat(nvidia-gpu): tweak setup
Browse files Browse the repository at this point in the history
  • Loading branch information
workflow committed Oct 20, 2024
1 parent 9d16b1a commit 1798db8
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 11 deletions.
5 changes: 5 additions & 0 deletions home.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
lib,
isNvidia,
pkgs,
secrets,
...
Expand Down Expand Up @@ -161,6 +162,10 @@ in {
BROWSER = "brave";
DEFAULT_BROWSER = "brave";
DIRENV_LOG_FORMAT = ""; # Disable verbose direnv output showing env variables changed
LIBVA_DRIVER_NAME =
if isNvidia
then "nvidia"
else null;
};
};

Expand Down
16 changes: 5 additions & 11 deletions machines/flexbox/system.nix
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
# Edit this configuration file to define what should be installed on
# your system. Help is available in the configuration.nix(5) man page
# and in the NixOS manual (accessible by running ‘nixos-help’).
{pkgs, ...}: 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 {
{...}: {
# Use the systemd-boot EFI boot loader.
boot.loader.systemd-boot.enable = true;
boot.loader.efi.canTouchEfiVariables = false; # Disable this after first installation to not wear out EFI storage
Expand All @@ -19,9 +11,11 @@ in {
boot.kernelParams = ["nvme_core.default_ps_max_latency_us=0" "acpiphp.disable=1"];

# GPU
environment.systemPackages = [nvidia-offload];
hardware.nvidia.prime = {
offload.enable = true;
offload = {
enable = true;
enableOffloadCmd = true;
};
intelBusId = "PCI:0:2:0";
nvidiaBusId = "PCI:1:0:0";
};
Expand Down
35 changes: 35 additions & 0 deletions system/nvidia/default.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,42 @@
# See: https://nixos.wiki/wiki/Nvidia
{pkgs, ...}: {
boot.blacklistedKernelModules = ["nouveau"];
environment.systemPackages = [
pkgs.nvtopPackages.full # nvtop
pkgs.mesa-demos
pkgs.vulkan-tools
pkgs.libva-utils
];
services.xserver.videoDrivers = ["nvidia"];
hardware.opengl = {
enable = true;
};

hardware.nvidia = {
# Modesetting is required.
modesetting.enable = true;

# Nvidia power management. Experimental, and can cause sleep/suspend to fail.
# Enable this if you have graphical corruption issues or application crashes after waking
# up from sleep. This fixes it by saving the entire VRAM memory to /tmp/ instead
# of just the bare essentials.
powerManagement.enable = false;

# Fine-grained power management. Turns off GPU when not in use.
# Experimental and only works on modern Nvidia GPUs (Turing or newer).
powerManagement.finegrained = true;

# Use the NVidia open source kernel module (not to be confused with the
# independent third-party "nouveau" open source driver).
# Support is limited to the Turing and later architectures. Full list of
# supported GPUs is at:
# https://github.com/NVIDIA/open-gpu-kernel-modules#compatible-gpus
# Only available from driver 515.43.04+
# Currently alpha-quality/buggy, so false is currently the recommended setting.
open = false;

# Enable the Nvidia settings menu,
# accessible via `nvidia-settings`.
nvidiaSettings = true;
};
}

0 comments on commit 1798db8

Please sign in to comment.