From 6e5cc385fc8cf5ca6495d70243074ccdea9f64c7 Mon Sep 17 00:00:00 2001 From: mexisme Date: Fri, 18 Aug 2023 22:33:16 +1200 Subject: [PATCH] Extract AMD-GPU from Nvidia, to make it easier to choose either --- lenovo/yoga/7/14ARH7/amdgpu/default.nix | 23 ++++++ lenovo/yoga/7/14ARH7/default.nix | 93 ++++--------------------- lenovo/yoga/7/14ARH7/nvidia/default.nix | 47 +++++++++++++ lenovo/yoga/7/14ARH7/shared.nix | 32 +++++++++ 4 files changed, 115 insertions(+), 80 deletions(-) create mode 100644 lenovo/yoga/7/14ARH7/amdgpu/default.nix create mode 100644 lenovo/yoga/7/14ARH7/nvidia/default.nix create mode 100644 lenovo/yoga/7/14ARH7/shared.nix diff --git a/lenovo/yoga/7/14ARH7/amdgpu/default.nix b/lenovo/yoga/7/14ARH7/amdgpu/default.nix new file mode 100644 index 0000000..4d16de0 --- /dev/null +++ b/lenovo/yoga/7/14ARH7/amdgpu/default.nix @@ -0,0 +1,23 @@ +# Including this file will enable the AMD-GPU driver + +{ lib, pkgs, ... }: + +let + inherit (lib) mkDefault; + +in { + imports = [ + ../shared.nix + ]; + + # AMD RX680 + services.xserver.videoDrivers = mkDefault [ "amdgpu" ]; + + hardware = { + amdgpu.loadInInitrd = true; + opengl.extraPackages = with pkgs; [ + vaapiVdpau + libvdpau-va-gl + ]; + }; +} diff --git a/lenovo/yoga/7/14ARH7/default.nix b/lenovo/yoga/7/14ARH7/default.nix index a1b21e7..851033c 100644 --- a/lenovo/yoga/7/14ARH7/default.nix +++ b/lenovo/yoga/7/14ARH7/default.nix @@ -1,82 +1,15 @@ -{ config, lib, pkgs, ... }: +# When using from a Flake, you can access these via imports of the attr key, e.g: +# +# imports = [ +# nixos-hardware.nixosModules.lenovo-yoga-7-14ARH7.amdgpu +# ]; +# +## or: +# imports = [ +# nixos-hardware.nixosModules.lenovo-yoga-7-14ARH7.nvidia +# ]; -let - inherit (lib) mkDefault mkMerge; - -in { - imports = [ - ../../../../common/cpu/amd - # Better power-savings from AMD PState: - ../../../../common/cpu/amd/pstate.nix - ../../../../common/gpu/amd - ## "prime.nix" loads this, aleady: - # ../../../../common/gpu/nvidia - ../../../../common/gpu/nvidia/prime.nix - ../../../../common/pc/laptop - ../../../../common/pc/laptop/acpi_call.nix - ../../../../common/pc/ssd - ]; - - config = mkMerge [ - { - # Configure basic system settings: - boot = { - kernelModules = [ "kvm-amd" ]; - kernelParams = [ - "mem_sleep_default=deep" - "pcie_aspm.policy=powersupersave" - - ## Supposed to help fix for suspend issues: SSD not correctly working, and Keyboard not responding: - ## Not needed for the 6.1+ kernels? - # "iommu=pt" - - ## Fixes for s2idle: - ## https://www.phoronix.com/news/More-s2idle-Rembrandt-Linux - # "acpi.prefer_microsoft_guid=1" - ## Appears to have been renamed? - "acpi.prefer_microsoft_dsm_guid=1" - ]; - - blacklistedKernelModules = [ "nouveau" ]; - }; - } - - { - ## Graphics settings - - ## AMD RX680 - # services.xserver.videoDrivers = mkDefault [ "amdgpu" ]; - - # NVIDIA GeForce RTX 3050 Mobile (Ampere) - services.xserver.videoDrivers = mkDefault [ "nvidia" ]; - - hardware = { - ## Enable the Nvidia card, as well as Prime and Offload: - amdgpu.loadInInitrd = true; - opengl.extraPackages = with pkgs; [ - vaapiVdpau - libvdpau-va-gl - ]; - - nvidia = { - modesetting.enable = true; - nvidiaSettings = true; - - prime = { - offload = { - enable = true; - enableOffloadCmd = true; - }; - amdgpuBusId = "PCI:4:0:0"; - nvidiaBusId = "PCI:1:0:0"; - }; - - powerManagement = { - enable = true; - # finegrained = true - }; - }; - }; - } - ]; +{ + amdgpu = import ./amdgpu; + nvidia = import ./nvidia; } diff --git a/lenovo/yoga/7/14ARH7/nvidia/default.nix b/lenovo/yoga/7/14ARH7/nvidia/default.nix new file mode 100644 index 0000000..fb4553e --- /dev/null +++ b/lenovo/yoga/7/14ARH7/nvidia/default.nix @@ -0,0 +1,47 @@ +# Including this file will enable the NVidia driver, and PRIME offload + +{ lib, pkgs, ... }: + +let + inherit (lib) mkDefault; + +in { + imports = [ + ../shared.nix + ## "prime.nix" loads this, aleady: + # ../../../../common/gpu/nvidia + ../../../../../common/gpu/nvidia/prime.nix + ]; + + # NVIDIA GeForce RTX 3050 Mobile (Ampere) + services.xserver.videoDrivers = mkDefault [ "nvidia" ]; + + hardware = { + ## Enable the Nvidia card, as well as Prime and Offload: + amdgpu.loadInInitrd = true; + opengl.extraPackages = with pkgs; [ + vaapiVdpau + libvdpau-va-gl + ]; + + nvidia = { + modesetting.enable = true; + nvidiaSettings = true; + + prime = { + offload = { + enable = true; + enableOffloadCmd = true; + }; + amdgpuBusId = "PCI:4:0:0"; + nvidiaBusId = "PCI:1:0:0"; + }; + + powerManagement = { + enable = true; + # Doesn't seem to be reliable, yet? + # finegrained = true + }; + }; + }; +} diff --git a/lenovo/yoga/7/14ARH7/shared.nix b/lenovo/yoga/7/14ARH7/shared.nix new file mode 100644 index 0000000..3bef447 --- /dev/null +++ b/lenovo/yoga/7/14ARH7/shared.nix @@ -0,0 +1,32 @@ +{ ... }: + +{ + imports = [ + ../../../../common/cpu/amd + # Better power-savings from AMD PState: + ../../../../common/cpu/amd/pstate.nix + ../../../../common/gpu/amd + ../../../../common/pc/laptop + ../../../../common/pc/laptop/acpi_call.nix + ../../../../common/pc/ssd + ]; + + # Configure basic system settings: + boot = { + kernelModules = [ "kvm-amd" ]; + kernelParams = [ + "mem_sleep_default=deep" + "pcie_aspm.policy=powersupersave" + + ## Supposed to help fix for suspend issues: SSD not correctly working, and Keyboard not responding: + ## Not needed for the 6.1+ kernels? + # "iommu=pt" + + ## Fixes for s2idle: + ## https://www.phoronix.com/news/More-s2idle-Rembrandt-Linux + "acpi.prefer_microsoft_dsm_guid=1" + ]; + + blacklistedKernelModules = [ "nouveau" ]; + }; +}