1
0
Fork 0
mirror of https://github.com/NixOS/nixos-hardware synced 2024-12-18 15:49:45 +01:00
This commit is contained in:
yuannan 2024-03-10 19:42:41 +00:00 committed by mergify[bot]
parent a3746a14c1
commit a7825c5b9a
6 changed files with 120 additions and 0 deletions

View file

@ -0,0 +1,30 @@
## Introduction
Due to the introduction of DDG feature, you may toggle DDG frequently, so for the default settings of this laptop, we use "specialization" feature of Nix so that you can easily select the required graphics card driver in the startup menu.
**But It will slow down NixOS evaluation by factor 2 and increase memory usage.**
So if you don't need specialization feature, you can just use hybrid only configuration or nvidia only (DDG only) configuration
## Using multiple drives with this configuration
When using more than one drive, the value of `hardware.nvidia.prime.amdgpuBusId` will change from the default of `PCI:5:0:0`.
Make sure you override this default in your personal configuration. For two drives, it should be `PCI:6:0:0`.
## Setup at the time of testing
```
$ nix-info -m
- system: `"x86_64-linux"`
- host os: `Linux 6.0.9, NixOS, 22.11 (Raccoon), 22.11beta19.c9538a9b707`
- multi-user?: `yes`
- sandbox: `yes`
- version: `nix-env (Nix) 2.11.0`
- channels(root): `"nixos-22.11"`
- nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos`
```
```
$ lspci
...
01:00.0 VGA compatible controller: NVIDIA Corporation GA104M [GeForce RTX 3070 Mobile / Max-Q] (rev a1)
...
06:00.0 VGA compatible controller: Advanced Micro Devices, Inc. [AMD/ATI] Cezanne (rev c5)
...
```

View file

@ -0,0 +1,11 @@
{ ... }:
{
imports = [ ./hybrid ];
specialisation.ddg.configuration = {
# This specialisation is for the case where "DDG" (Dual-Direct GFX, A hardware feature that can enable in bios) is enabled, since the amd igpu is blocked at hardware level and the built-in display is directly connected to the dgpu, we no longer need the amdgpu and prime configuration.
system.nixos.tags = [ "Dual-Direct-GFX-Mode" ];
imports = [ ./nvidia ];
};
}

Binary file not shown.

View file

@ -0,0 +1,17 @@
{ pkgs, ... }:
let
# This file was obtained from the display while "DDG" mode was enabled.
chip_edid = pkgs.runCommandNoCC "chip_edid" { } ''
mkdir -p $out/lib/firmware/edid
cp ${./15ach6h.bin} $out/lib/firmware/edid/15ach6h.bin
'';
in
{
hardware.firmware = [ chip_edid ];
boot.kernelParams = [ "drm.edid_firmware=edid/15ach6h.bin" ];
# This fails at the moment, https://github.com/NixOS/nixos-hardware/issues/795
# Extra refresh rates seem to work regardless
# boot.initrd.extraFiles."lib/firmware/edid/15ach6h.bin".source = pkgs.runCommandLocal "chip_edid" { } "cp ${./15ach6h.bin} $out";
}

View file

@ -0,0 +1,36 @@
{ lib, ... }:
{
imports = [
../../../../common/cpu/amd
../../../../common/cpu/amd/pstate.nix
../../../../common/gpu/amd
../../../../common/gpu/nvidia/prime.nix
../../../../common/pc/laptop
../../../../common/pc/laptop/ssd
../edid
];
# Still needs to load at some point if we want X11 to work
boot.kernelModules = [ "amdgpu" ];
# modesetting just doesn't work (on X11?), so get rid of it by only explicitly declaring nvidia
# Needed due to https://github.com/NixOS/nixos-hardware/commit/630a8e3e4eea61d35524699f2f59dbc64886357d
# See also https://github.com/NixOS/nixos-hardware/issues/628
# options.services.xserver.drivers will have a amdgpu entry from using the prime stuff in nixpkgs
services.xserver.videoDrivers = [ "nvidia" ];
hardware = {
amdgpu.loadInInitrd = lib.mkDefault false;
nvidia = {
modesetting.enable = lib.mkDefault true;
powerManagement.enable = lib.mkDefault true;
prime = {
amdgpuBusId = lib.mkDefault "PCI:6:0:0";
nvidiaBusId = "PCI:1:0:0";
};
};
};
}

View file

@ -0,0 +1,26 @@
{ ... }:
{
imports = [ ../hybrid ];
services.xserver.videoDrivers = [ "nvidia" ]; # This will override services.xserver.videoDrivers = lib.mkDefault [ "amdgpu" "nvidia" ];
# When I play the game through proton, I found that in the case of Dual-Direct GFX
# enabled (dGPU disabled), proton will crash directly. But in the case of hybrid,
# the game runs fine with or without nvidia-offload After investigation, this is
# because when writing the specialization of Dual-Direct GFX, I did not completely
# remove all packages for amd igpu. I only removed amdgpu from
# services.xserver.videoDrivers by overriding. This is because the specialization
# of nix cannot implement such an operation as canceling an import. In the end, if
# it is enabled in Dual-Direct GFX In the absence of amd igpu, the amdvlk package
# caused the proton to crash. In order to solve this problem, I add the option of
# whether to enable amdvlk to the configuration file of amd gpu, and open it by
# default, and turn it off in specialization, so as to delete amdvlk package and
# other packages for amd igpu in specialization. At the same time, I also added an
# option to amdgpu's opencl runtime.
hardware = {
nvidia.prime.offload.enable = false;
amdgpu = {
amdvlk = false;
opencl = false;
};
};
}