tpwrules / nixos-apple-silicon

Resources to install NixOS bare metal on Apple Silicon Macs
MIT License
838 stars 80 forks source link

Audio/headphones support #54

Closed shaunsingh closed 11 months ago

shaunsingh commented 1 year ago

Hi, I'd love to get audio and headphones working on nixos-apple-silicon, but I'm not quite sure how. From what I understand it should be a matter of adding the asahi ucm configuration to the alsa-ucm-conf package but it still doesn't quite work

Heres my current attempt with an overlay in my config, where inputs.asahi-alsa-src points to [asahi's configuration(https://github.com/AsahiLinux/alsa-ucm-conf-asahi)

alsa-ucm-conf = prev.alsa-ucm-conf.overrideAttrs (old: rec {
  installPhase = ''
    runHook preInstall
    mkdir -p $out/share/alsa
    cp -r ucm ucm2 $out/share/alsa
    cp -r ${inputs.asahi-alsa-src}/ucm2/conf.d/macaudio $out/share/alsa/ucm2/conf.d/macaudio
    runHook postInstall
  '';
});
yusefnapora commented 1 year ago

I have headphones working on my 14" M1 Pro, but it took me a minute to figure that out, since the DAC volume for the headphone jack was set to zero. This is independent of the pipewire / pulseaudio volume, so it wasn't really obvious what was wrong.

What works for me is to use alsamixer or amixer from the alsa-utils package and set the "Jack DAC" volume. With alsamixer, you need to press F6 and select the audio device (device name should start with "MacBook"), then use the arrow keys to select the "Jack DAC" slider and increase it.

Mine resets to zero on reboot, so I run ${pkgs.alsa-utils}/bin/amixer -c 1 set 'Jack DAC' 100% in a startup hook for my window manager. The -c 1 chooses the "card number", which shows up in alsamixer when switching devices with F6. On mine, the default:0 card is a loopback device, and default:1 is my actual hardware, so that's why I'm using -c 1. You might not have a loopback device; mine showed up randomly a little while ago for reasons unknown (maybe wireplumber?).

shaunsingh commented 1 year ago

20230225_11h24m56s_grim

For me the macbook audio device doesn't show up at all, running a macbook pro M1 13 inch.

shaunsingh commented 1 year ago

Finally got it working with the following:

First make an overlay of alsa-utils that adds the proper configurations to alsa

asahi-alsa-utils = prev.alsa-utils.override {
  alsa-lib = prev.alsa-lib.override {
    alsa-ucm-conf = prev.alsa-ucm-conf.overrideAttrs (_: {
      installPhase = ''
        runHook preInstall
        mkdir -p $out/share/alsa
        cp -r ucm ucm2 $out/share/alsa
        cp -r ${asahi-alsa-src}/ucm2/conf.d/macaudio $out/share/alsa/ucm2/conf.d/macaudio
        runHook postInstall
      '';
    });
  };
};

I found that my audio device for the macbook is #0 (hence -c 0) and that instead of Jack DAC its named Jack Mixer. Running the following sets the volume for me (the startup is from the sway home-manager module, I imagine you could use a systemd service to do the same thing)

startup = [
  {command = "${pkgs.asahi-alsa-utils}/bin/amixer -c 0 set 'Jack Mixer' 100%";}
];
yusefnapora commented 1 year ago

Awesome!

shaunsingh commented 1 year ago

the above fix has mysteriously stopped working for me and I have absolutely no idea why

venikx commented 1 year ago

20230225_11h24m56s_grim

For me the macbook audio device doesn't show up at all, running a macbook pro M1 13 inch.

Does this still happen? I have the same specs as you, but I seem to receive devices (I installed the 24/06/2023 version.)

shaunsingh commented 1 year ago

I stopped using Asahi a few months back, but it worked sometimes and didn't work other times

tpwrules commented 11 months ago

I'm not sure what the DAC volume issues are about, I didn't need to change that but it seems sometimes that the system volume is louder than other times. Anyway, audio support will be available in the next release.