Can't get alsa + nixos working

  1. Disable hardware.pulseaudio.enable, remove everything sound-related from your boot.extraModprobeConfig. Keep only the sound.enable = true line.
  2. Rebuild. Reboot.
  3. Check that no PulseAudio daemon is running.
  4. Remove/rename /etc/asound.conf and ~/.asoundrc, if any.

You’re now in the pristine state. You want to be in pristine state, 99.9% of ALSA problems come from misconfiguration by users and by PulseAudio (it changes asound.conf to route sound from ALSA default PCM to itself). You don’t want that, you want pristine state.

If you are not in the pristine state don’t blame ALSA and the stuff below for not working. You have been warned.

  1. Run aplay -l. You should see at least two sound cards.

E.g. on my laptop:

card 0: PCH [HDA Intel PCH], device 0: ALC269VC Analog [ALC269VC Analog]
  Subdevices: 0/1
  Subdevice #0: subdevice #0
card 0: PCH [HDA Intel PCH], device 3: HDMI 0 [HDMI 0]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: PCH [HDA Intel PCH], device 7: HDMI 1 [HDMI 1]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: PCH [HDA Intel PCH], device 8: HDMI 2 [HDMI 2]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: AUDIO [USB AUDIO], device 0: USB Audio [USB Audio]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
  1. Write the following to /etc/asound.conf:

(assuming you want Intel HDA to be the default)

defaults.pcm.!card "PCH"
defaults.ctl.!card "PCH"

(or, assuming you want USB sound card to be the default)

defaults.pcm.!card "AUDIO"
defaults.ctl.!card "AUDIO"

(The string after “:” in the output of aplay -l is the ID.)

  1. Check that /etc/asound.conf is readable by your normal user.
  2. Run alsamixer and unmute (“M” key) and set non-zero volume (up-down keys) for everything.
  3. Check that sound works via pure ALSA with speaker-test -c 2, aplay, mpv, or whatever else (but be sure to check that the tool you check it with doesn’t try to start PulseAudio daemon, speaker-test and aplay won’t, mpv might).
  4. After and only after you checked that the pure ALSA output works, enable PulseAudio (if you still need it for some reason, hint: most likely, you don’t, software mixing works with ALSA out of the box for over a decade now).
6 Likes