This guide details the process to resolve the lack of sound from the internal speakers on the Lenovo Legion Pro 7 16IRX9H notebook running NixOS. The issue occurs because the default audio driver (snd_hda_intel
) fails to correctly initialize the amplifiers for the Realtek ALC287 codec present in this hardware.
The solution involves applying a specific firmware patch declaratively, leveraging the robustness of NixOS.
Thanks to Felipe "Noksys" Lalli for debugging and documenting the solution in his NixOS configuration repository, noksys/genoc.
First, you need a patch file containing the "verbs" (low-level commands) for the audio codec. Create a file named legion-alc287.patch
in your NixOS configuration directory (e.g., /etc/nixos/hardware/
).
Contents of legion-alc287.patch
:
[codec]
0x10ec0287 0x17aa38fe 0
[verb]
0x20 0x500 0x1b
0x20 0x400 0x7774
This patch instructs the codec to enable the necessary components for the speakers.
Now, edit your hardware configuration file in NixOS (commonly hardware-configuration.nix
or a machine-specific file, like /etc/nixos/mica-nixos/genoc/hardware/lenovo-legion-pro7-16irx9h.nix
in the original case) to make the system aware of and apply the patch.
Add the following sections to your .nix
configuration file:
{ pkgs, ... }:
{
# ... other configurations ...
# 1. Copy the patch to the system's firmware directory.
# This ensures the patch is available to the kernel at boot.
hardware.firmware = [
(pkgs.runCommandNoCC "legion-audio-patch" {} ''
mkdir -p $out/lib/firmware
# Make sure the path to the patch is correct!
# The path './legion-alc287.patch' assumes the patch is
# in the same directory as this .nix file.
cp ./legion-alc287.patch $out/lib/firmware/legion-alc287.patch
'')
];
# 2. Instruct the 'snd_hda_intel' kernel module to use the patch.
boot.extraModprobeConfig = ''
options snd-hda-intel patch=legion-alc287.patch
'';
# ... rest of the configurations ...
}
Note: If you already have a boot.extraModprobeConfig
or hardware.firmware
section, just add the new entries to them.
With the configurations saved, apply them by rebuilding your NixOS system:
sudo nixos-rebuild switch
After the rebuild completes successfully, reboot your computer. The kernel will load the audio module with the patch applied, and the sound from the internal speakers should now work perfectly.
I’ve noticed that after it runs for a while, it stops working—for me too. I got these values from Google somewhere, but I don’t remember where. Yeah… It really doesn’t look like a definitive solution yet. Should I delete it or keep it here?