Enable nvidia and move nvidia config to separate file
- Enable nvidia GPU in sync-mode At least one game did not work well enough on Intel - Move nvidia config to separate file (nvidia.nix) - Refactor and simplify nvidia config enabling/mode-changing of nvidia can be done via two simple top-level variables instead of changing interdependent booleans independently. select GPU driver based on top level variable Add `nvidia-offload' environment variable shell to env based on top-level variable
This commit is contained in:
parent
d2fd09fd5c
commit
28322523c8
3 changed files with 60 additions and 21 deletions
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
description = "Payas' NixOS configuration (flake edition)";
|
||||
description = "NixOS configuration (flake edition)";
|
||||
|
||||
inputs = {
|
||||
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
|
||||
|
@ -28,6 +28,7 @@
|
|||
(import ./nix.nix)
|
||||
(import ./hosts/enterprise/sound.nix)
|
||||
(import ./hosts/enterprise/backup.nix)
|
||||
(import ./hosts/enterprise/nvidia.nix)
|
||||
(import ./cachix.nix)
|
||||
{ nixpkgs.overlays = [ emacs-overlay.overlay ]; }
|
||||
home-manager.nixosModules.home-manager
|
||||
|
|
|
@ -74,19 +74,6 @@ in
|
|||
enableRedistributableFirmware = true;
|
||||
acpilight.enable = true;
|
||||
|
||||
nvidiaOptimus.disable = true;
|
||||
nvidia = {
|
||||
package = config.boot.kernelPackages.nvidiaPackages.stable;
|
||||
modesetting.enable = false; # Same as sync.enable
|
||||
prime = {
|
||||
# Bus ID of the Intel GPU. You can find it using lspci, either under 3D or VGA
|
||||
intelBusId = "PCI:0:2:0";
|
||||
# Bus ID of the NVIDIA GPU. You can find it using lspci, either under 3D or VGA
|
||||
nvidiaBusId = "PCI:1:0:0";
|
||||
sync.enable = false; # Complement of offload.enable
|
||||
offload.enable = false;
|
||||
};
|
||||
};
|
||||
opengl = {
|
||||
enable = true;
|
||||
driSupport32Bit = true;
|
||||
|
@ -130,11 +117,6 @@ in
|
|||
};
|
||||
# Enable touchpad support.
|
||||
libinput.enable = true;
|
||||
videoDrivers = [
|
||||
# Keep only "nvidia" when using sync-mode
|
||||
"intel" # "intel" "nvidia"
|
||||
# "nvidia"
|
||||
];
|
||||
};
|
||||
# Enable tlp for power/battery management
|
||||
tlp.enable = true;
|
||||
|
@ -249,8 +231,6 @@ in
|
|||
pathsToLink = [ "/share/nix-direnv" ];
|
||||
|
||||
systemPackages = with pkgs; [
|
||||
# Nvidia packages
|
||||
primus
|
||||
glxinfo
|
||||
inxi
|
||||
|
||||
|
|
58
hosts/enterprise/nvidia.nix
Normal file
58
hosts/enterprise/nvidia.nix
Normal file
|
@ -0,0 +1,58 @@
|
|||
{ config, pkgs, options, ... }:
|
||||
|
||||
let
|
||||
nvidiaEnabled = true;
|
||||
nvidiaAlwaysOn = true;
|
||||
|
||||
# For some reason at least one game needs this to be set,
|
||||
# even if nvidia GPU is in sync-mode
|
||||
# Could be Wayland, needs further investigation
|
||||
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
|
||||
{
|
||||
config = {
|
||||
hardware = {
|
||||
nvidiaOptimus.disable = !nvidiaEnabled;
|
||||
nvidia = {
|
||||
package = config.boot.kernelPackages.nvidiaPackages.stable;
|
||||
modesetting.enable = nvidiaAlwaysOn; # Same as sync.enable
|
||||
powerManagement = {
|
||||
# Only for offload.enable=true
|
||||
enable = !nvidiaAlwaysOn;
|
||||
finegrained = !nvidiaAlwaysOn;
|
||||
};
|
||||
prime = {
|
||||
# Bus ID of the Intel GPU. You can find it using lspci, either under 3D or VGA
|
||||
intelBusId = "PCI:0:2:0";
|
||||
# Bus ID of the NVIDIA GPU. You can find it using lspci, either under 3D or VGA
|
||||
nvidiaBusId = "PCI:1:0:0";
|
||||
sync.enable = nvidiaAlwaysOn; # Complement of offload.enable
|
||||
offload.enable = !nvidiaAlwaysOn;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
services.xserver.videoDrivers =
|
||||
if nvidiaEnabled
|
||||
then
|
||||
[ "nvidia" ] # Keep only "nvidia" when using sync-mode
|
||||
else
|
||||
[ "intel" ];
|
||||
|
||||
environment.systemPackages =
|
||||
with pkgs;
|
||||
(if nvidiaEnabled
|
||||
then [
|
||||
nvidia-offload
|
||||
primus
|
||||
]
|
||||
else
|
||||
[ ]);
|
||||
};
|
||||
}
|
Reference in a new issue