Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save felipelalli/6179aac72735fd35ea3a9854beb490e5 to your computer and use it in GitHub Desktop.
Save felipelalli/6179aac72735fd35ea3a9854beb490e5 to your computer and use it in GitHub Desktop.
Guide: Fixing Speaker Audio on Lenovo Legion Pro 7 with NixOS

Guide: Fixing Speaker Audio on Lenovo Legion Pro 7 with NixOS

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.


Step 1: Create the Patch File

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.

Step 2: Modify the NixOS Configuration

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.

Step 3: Rebuild the System

With the configurations saved, apply them by rebuilding your NixOS system:

sudo nixos-rebuild switch

Step 4: Reboot

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.

Guia: Corrigindo o Áudio dos Alto-Falantes no Lenovo Legion Pro 7 com NixOS

Este guia detalha o processo para resolver a ausência de som nos alto-falantes internos do notebook Lenovo Legion Pro 7 16IRX9H rodando NixOS. O problema ocorre porque o driver de áudio padrão (snd_hda_intel) não consegue inicializar corretamente os amplificadores do codec Realtek ALC287 presente neste hardware.

A solução envolve aplicar um patch de firmware específico de forma declarativa, aproveitando a robustez do NixOS.

Agradecimentos ao Felipe "Noksys" Lalli por depurar e documentar a solução em seu repositório de configurações do NixOS, noksys/genoc.


Passo 1: Criar o Arquivo de Patch

Primeiro, você precisa de um arquivo de patch que contém os "verbos" (comandos de baixo nível) para o codec de áudio. Crie um arquivo chamado legion-alc287.patch em seu diretório de configuração do NixOS (por exemplo, /etc/nixos/hardware/).

Conteúdo do legion-alc287.patch:

[codec]
0x10ec0287 0x17aa38fe 0

[verb]
0x20 0x500 0x1b
0x20 0x400 0x7774

Este patch instrui o codec a ativar os componentes necessários para os alto-falantes.

Passo 2: Modificar a Configuração do NixOS

Agora, edite o arquivo de configuração do seu hardware no NixOS (comumente hardware-configuration.nix ou um arquivo específico do seu computador, como /etc/nixos/mica-nixos/genoc/hardware/lenovo-legion-pro7-16irx9h.nix no caso original) para que o sistema conheça e aplique o patch.

Adicione as seguintes seções ao seu arquivo de configuração .nix:

{ pkgs, ... }:

{
  # ... outras configurações ...

  # 1. Copia o patch para o diretório de firmware do sistema.
  #    Isso garante que o patch esteja disponível para o kernel no boot.
  hardware.firmware = [
    (pkgs.runCommandNoCC "legion-audio-patch" {} ''
      mkdir -p $out/lib/firmware
      # Certifique-se de que o caminho para o patch está correto!
      # O caminho './legion-alc287.patch' assume que o patch está
      # no mesmo diretório que este arquivo .nix.
      cp ./legion-alc287.patch $out/lib/firmware/legion-alc287.patch
    '')
  ];

  # 2. Instrui o módulo do kernel 'snd_hda_intel' a usar o patch.
  boot.extraModprobeConfig = ''
    options snd-hda-intel patch=legion-alc287.patch
  '';

  # ... resto das configurações ...
}

Observação: Se você já tiver uma seção boot.extraModprobeConfig ou hardware.firmware, apenas adicione as novas entradas a elas.

Passo 3: Reconstruir o Sistema

Com as configurações salvas, aplique-as reconstruindo seu sistema NixOS:

sudo nixos-rebuild switch

Passo 4: Reiniciar

Após a reconstrução ser concluída com sucesso, reinicie o seu computador. O kernel irá carregar o módulo de áudio com o patch aplicado, e o som dos alto-falantes internos deverá funcionar perfeitamente.

@ovitente
Copy link

ovitente commented Jul 16, 2025

Thank you for the solution!

But i was not able to reproduce it following your guide.

The issue was with the path used in cp command, it does not work even when you set full path to the file. As-well as related path.

    firmware = [
      (pkgs.runCommandNoCC "legion-audio-patch" {} ''
        mkdir -p $out/lib/firmware
        cp /etc/nixos/nixos-hardware/lenovo/legion/16irx8h/legion-alc287.patch $out/lib/firmware/legion-alc287.patch
      '')
    ];

root@serenity:/etc/nixos/ > nixos-rebuild switch
building Nix...
building the system configuration...
these 10 derivations will be built:
  /nix/store/kjlflgr8qs1qhz7wyz7xnfx6gdrd64dg-legion-audio-patch.drv
 ...
  /nix/store/cypf8rbbn5589wmq4i7w4fw6dsks2lw1-nixos-system-serenity-25.05.805252.b43c397f6c21.drv
building '/nix/store/kjlflgr8qs1qhz7wyz7xnfx6gdrd64dg-legion-audio-patch.drv'...

cp: cannot stat '/etc/nixos/nixos-hardware/lenovo/legion/16irx8h/legion-alc287.patch': No such file or directory

...
error: 1 dependencies of derivation '/nix/store/cypf8rbbn5589wmq4i7w4fw6dsks2lw1-nixos-system-serenity-25.05.805252.b43c397f6c21.drv' failed to build

And cursor fixed it for me with this approach

    firmware = [
      (pkgs.runCommandNoCC "legion-audio-patch" { src = ./legion-alc287.patch; } ''
        mkdir -p $out/lib/firmware
        cp $src $out/lib/firmware/legion-alc287.patch
      '')
    ];

But solution did not fixed the issue, even after reboot. Unfortunately :(
Everything the same, 1 minute after reboot sound works, different sources, and when i close all sound sources for several seconds - it never back after that. Not local player, not youtube in different browsers, nothing work. The same lenovo shit.

Absoulutely the same laptop. Just different date of release. Mine 16irx8h, his - 16irx9h.

@Prn-Ice
Copy link

Prn-Ice commented Jul 21, 2025

Hi.
Thanks a lot for the guide.
I'd like to test this out on my computer.
I have the Legion Slim 7 Gen 8 16APH8.

How did you get these values? Do I have to tweak them for my computer.

[codec]
0x10ec0287 0x17aa38fe 0

[verb]
0x20 0x500 0x1b
0x20 0x400 0x7774

Sometimes I hear my speaker pop before it stops working.
I also get a ton of these logs when my speaker starts and stops.
i2c_designware AMDI0010:03: i2c_dw_handle_tx_abort: lost arbitration

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment