Can't get alsa + nixos working

I’m trying to get my sound working on a nixos machine using alsa and pulseaudio.
I followed the steps in ALSA - NixOS Wiki, but I can’t get my default audio card to be the intel sound card (it’s stuck at a default with only one vertical bar in alsamixer).
I tried everything suggested in the alsa + nixos wiki, but nothing seems to work for me.
Does anyone have any ideas for what to try next?

Output of some commands:

$ lsmod | grep snd
snd_hda_codec_hdmi     61440  1
snd_hda_codec_realtek    90112  1
snd_hda_codec_generic    81920  1 snd_hda_codec_realtek
snd_soc_skl            90112  0
snd_soc_skl_ipc        65536  1 snd_soc_skl
snd_soc_sst_ipc        16384  1 snd_soc_skl_ipc
snd_soc_sst_dsp        28672  1 snd_soc_skl_ipc
snd_hda_ext_core       24576  1 snd_soc_skl
snd_soc_sst_match      16384  1 snd_soc_skl
snd_soc_core          233472  1 snd_soc_skl
snd_compress           24576  1 snd_soc_core
ac97_bus               16384  1 snd_soc_core
snd_pcm_dmaengine      16384  1 snd_soc_core
snd_usb_audio         188416  2
snd_usbmidi_lib        32768  1 snd_usb_audio
snd_rawmidi            28672  1 snd_usbmidi_lib
snd_seq_device         16384  1 snd_rawmidi
snd_hda_intel          36864  3
snd_hda_codec         126976  4 snd_hda_codec_generic,snd_hda_codec_hdmi,snd_hda_intel,snd_hda_codec_realtek
snd_hda_core           73728  7 snd_hda_codec_generic,snd_hda_codec_hdmi,snd_hda_intel,snd_hda_ext_core,snd_hda_codec,snd_hda_codec_realtek,snd_soc_skl
snd_hwdep              16384  2 snd_usb_audio,snd_hda_codec
snd_pcm               102400  9 snd_hda_codec_hdmi,snd_hda_intel,snd_usb_audio,snd_hda_ext_core,snd_hda_codec,snd_soc_core,snd_soc_skl,snd_hda_core,snd_pcm_dmaengine
snd_timer              32768  1 snd_pcm
snd                    73728  25 snd_hda_codec_generic,snd_seq_device,snd_hda_codec_hdmi,snd_hwdep,snd_hda_intel,snd_usb_audio,snd_usbmidi_lib,snd_hda_codec,snd_hda_codec_realtek,snd_timer,snd_compress,thinkpad_acpi,snd_soc_core,snd_pcm,snd_rawmidi
soundcore              16384  1 snd
usbcore               249856  9 xhci_hcd,snd_usb_audio,usbhid,snd_usbmidi_lib,usb_storage,uvcvideo,btusb,xhci_pci,uas
$ amixer
Simple mixer control 'Master',0
  Capabilities: pvolume pswitch pswitch-joined
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 65536
  Mono:
  Front Left: Playback 65536 [100%] [on]
  Front Right: Playback 65536 [100%] [on]
Simple mixer control 'Capture',0
  Capabilities: cvolume cswitch cswitch-joined
  Capture channels: Front Left - Front Right
  Limits: Capture 0 - 65536
  Front Left: Capture 65535 [100%] [on]
  Front Right: Capture 65535 [100%] [on]

From the nixos config:

  boot.extraModprobeConfig = ''
    options snd slots=snd-hda-intel
    options snd_hda_intel enable=0,1
  '';
  hardware.pulseaudio.enable = true;
  sound.enable = true;

Extra info:

$ ls -ltr ~/.config/pulse/*default*
-rw-r--r-- 1 nick.van.den.broeck users    1 09/08/18 - 15:09 ca6beeca427f4f09bdf0a90a5d287ced-default-sink
-rw-r--r-- 1 nick.van.den.broeck users    1 09/08/18 - 15:09 ca6beeca427f4f09bdf0a90a5d287ced-default-source

Note that both files are completely empty. A colleague of mine, whose sound is working, has non-empty files here:

(Colleague's files!!!)
$ cat ~/.config/pulse/e40ef0293b384aeb83305e31ffbe4b9c-default-sink  
alsa_output.pci-0000_00_1b.0.analog-stereo
$ cat ~/.config/pulse/e40ef0293b384aeb83305e31ffbe4b9c-default-source 
alsa_input.pci-0000_00_1b.0.analog-stereo
$ lspci | grep -i audio
00:1f.3 Audio device: Intel Corporation Sunrise Point-LP HD Audio (rev 21)

Final note: my user is in the “audio” group.

  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).
4 Likes

Thank you for the help! The speaker sound works again (and without pulseaudio, just using alsa and amixer to control the volume etc.).

Two things remain broken about my audio, though I have no idea whether they’re related to alsa:

  • When I plug in a headset, the sound stops through the speaker, but it doesn’t start in the headset. Amixer and alsamixer don’t show any difference given a plugged-in headset.
  • My mic doesn’t give any response to sound.
    Would you have any idea how to fix these?

Thank you for the help! The speaker sound works again (and without pulseaudio, just using alsa and amixer to control the volume etc.).

You’re welcome. That’s the way it should be, btw. PulseAudio adds no useful service. For running shitty apps that require PulseAudio API check out apulse package.

  • When I plug in a headset, the sound stops through the speaker, but it doesn’t start in the headset. Amixer and alsamixer don’t show any difference given a plugged-in headset.

Look for “Headphone” toggles in alsamixer (do amixer | grep -i head) and unmute those. If there are none, then I can only recommend to search the web specifically about your hardware.

  • My mic doesn’t give any response to sound.

With sound output working the easiest way is to run

arecord -f cd - | aplay -f cd -

and while running the above to experiment with capture mute toggles and volumes in alsamixer (press F4 to see them, see the navbar on the top of the UI, you can switch cards you configure by pressing F6 there btw).

2 Likes

There is a “Headphone” in alsamixer, but when it’s unmuted, I still can’t hear anything…
In “capture”, mic stuff is shown, and I can change the volume (though it’s not actually working), but there is no mute toggle button there (unlike the master/headphone/speaker/…).

There is a “Headphone” in alsamixer, but when it’s unmuted, I still can’t hear anything…

Are your sure you headphones actually physically work?

In “capture”, mic stuff is shown, and I can change the volume (though it’s not actually working), but there is no mute toggle button there (unlike the master/headphone/speaker/…).

And arecord -f cd - | aplay -f cd - still produces nothing?

Please share full outputs of

  • aplay -l
  • arecord -l
  • amixer
  • lspci | grep Audio

The headphones work on another laptop, yes.

$ aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: PCH [HDA Intel PCH], device 0: ALC285 Analog [ALC285 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 0: PCH [HDA Intel PCH], device 9: HDMI 3 [HDMI 3]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: PCH [HDA Intel PCH], device 10: HDMI 4 [HDMI 4]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: Audio [ThinkPad Dock USB Audio], device 0: USB Audio [USB Audio]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

$ arecord -l
**** List of CAPTURE Hardware Devices ****
card 0: PCH [HDA Intel PCH], device 0: ALC285 Analog [ALC285 Analog]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: Audio [ThinkPad Dock USB Audio], device 0: USB Audio [USB Audio]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

$ amixer
Simple mixer control 'Master',0
  Capabilities: pvolume pvolume-joined pswitch pswitch-joined
  Playback channels: Mono
  Limits: Playback 0 - 87
  Mono: Playback 47 [54%] [-30.00dB] [on]
Simple mixer control 'Headphone',0
  Capabilities: pvolume pswitch
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 87
  Mono:
  Front Left: Playback 87 [100%] [0.00dB] [on]
  Front Right: Playback 87 [100%] [0.00dB] [on]
Simple mixer control 'Speaker',0
  Capabilities: pvolume pswitch
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 87
  Mono:
  Front Left: Playback 87 [100%] [0.00dB] [on]
  Front Right: Playback 87 [100%] [0.00dB] [on]
Simple mixer control 'PCM',0
  Capabilities: pvolume
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 255
  Mono:
  Front Left: Playback 255 [100%] [0.00dB]
  Front Right: Playback 255 [100%] [0.00dB]
Simple mixer control 'Mic Boost',0
  Capabilities: volume
  Playback channels: Front Left - Front Right
  Capture channels: Front Left - Front Right
  Limits: 0 - 3
  Front Left: 3 [100%] [30.00dB]
  Front Right: 3 [100%] [30.00dB]
Simple mixer control 'IEC958',0
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [on]
Simple mixer control 'IEC958',1
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [on]
Simple mixer control 'IEC958',2
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [on]
Simple mixer control 'IEC958',3
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [on]
Simple mixer control 'IEC958',4
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [on]
Simple mixer control 'Capture',0
  Capabilities: cvolume cswitch
  Capture channels: Front Left - Front Right
  Limits: Capture 0 - 63
  Front Left: Capture 63 [100%] [30.00dB] [off]
  Front Right: Capture 63 [100%] [30.00dB] [off]
Simple mixer control 'Auto-Mute Mode',0
  Capabilities: enum
  Items: 'Disabled' 'Enabled'
  Item0: 'Disabled'
Simple mixer control 'Digital',0
  Capabilities: cvolume
  Capture channels: Front Left - Front Right
  Limits: Capture 0 - 120
  Front Left: Capture 120 [100%] [30.00dB]
  Front Right: Capture 120 [100%] [30.00dB]
Simple mixer control 'Internal Mic Boost',0
  Capabilities: volume
  Playback channels: Front Left - Front Right
  Capture channels: Front Left - Front Right
  Limits: 0 - 3
  Front Left: 3 [100%] [30.00dB]
  Front Right: 3 [100%] [30.00dB]

$ lspci | grep Audio
00:1f.3 Audio device: Intel Corporation Sunrise Point-LP HD Audio (rev 21)

$ lspci | grep Audio
00:1f.3 Audio device: Intel Corporation Sunrise Point-LP HD Audio (rev 21)

This is something unfamiliar. What model of Thinkpad is that?

Simple mixer control ‘Capture’,0
Capabilities: cvolume cswitch
Capture channels: Front Left - Front Right
Limits: Capture 0 - 63
Front Left: Capture 63 [100%] [30.00dB] [off]
Front Right: Capture 63 [100%] [30.00dB] [off]

  1. [off] is muted. Ah, right. In alsamixer capture sinks are selected with , not . Sorry about that. Enable it with .

Simple mixer control ‘Mic Boost’,0
Capabilities: volume
Playback channels: Front Left - Front Right
Capture channels: Front Left - Front Right
Limits: 0 - 3
Front Left: 3 [100%] [30.00dB]
Front Right: 3 [100%] [30.00dB]

Simple mixer control ‘Internal Mic Boost’,0
Capabilities: volume
Playback channels: Front Left - Front Right
Capture channels: Front Left - Front Right
Limits: 0 - 3
Front Left: 3 [100%] [30.00dB]
Front Right: 3 [100%] [30.00dB]

  1. It’s generally recommended to keep these at 0 for better capture quality, but YMMV. Play with it after you get capture working.

Simple mixer control ‘IEC958’,0
Capabilities: pswitch pswitch-joined
Playback channels: Mono
Mono: Playback [on]
Simple mixer control ‘IEC958’,1
Capabilities: pswitch pswitch-joined
Playback channels: Mono
Mono: Playback [on]
Simple mixer control ‘IEC958’,2
Capabilities: pswitch pswitch-joined
Playback channels: Mono
Mono: Playback [on]
Simple mixer control ‘IEC958’,3
Capabilities: pswitch pswitch-joined
Playback channels: Mono
Mono: Playback [on]
Simple mixer control ‘IEC958’,4
Capabilities: pswitch pswitch-joined
Playback channels: Mono
Mono: Playback [on]

  1. Some or all of those might need disabling for some of other things to work. I think it’s very unlikely these influence headphones, but it’s worth a try.

Also, looking at the outputs, if I were you I would also experiment with routing sound through the USB dock audio. I would start the experiment with speaker-test -c 2 -D hw:Audio, see what happens, and go from there.

Another approach (and I do know how Jan feels about pulseaudio) is to simply let pulseaudio take care of things - in my experience things just work out of the box with the following:

  1. Blow away whatever local alsa config you may have
  2. Enable pulseaudio with defaults:
hardware.pulseaudio.enable = true;
sound.enable = true;
  1. Install the pulseaudio control application:
environment.systemPackages = with pkgs; [ lxqt.pavucontrol-qt ];

You should be able to configure all your devices/streams from pavucontrol-qt.

EDIT: since people are still referring to the post, I would like to point out that in 2023 you should be using pipewire instead of puleaudio.

3 Likes

thank you peterhoeg. although the pure alsa suggestion is working. I prefer the lxqt.pavucontrol-qt solution which does the trick for me

1 Like