Issue after sound option was removed in unstable

I use unstable NixOS and when upgrading the channel I had the following error:

The option definition sound in /etc/nixos/configuration.nix no longer has any effect; please remove it

Casued by

sound.enable = true;

I removed this option and then upgraded my system, but now every time I turn on my PC the speakers give off a popping sound. Is there some other option I could use to fix this?

My full audio config right now is as follows:

	# Enable sound.
	security.rtkit.enable = true;
	services.pipewire = {
		enable = true;
		audio.enable = true;
		jack.enable = true;
		pulse.enable = true;
		alsa = {
			enable = true;
			support32Bit = true;
		};
	};
1 Like

You can look through the old module and check if any of the options there help; if they do, that should probably be added to the migration doc: nixpkgs/nixos/modules/services/audio/alsa.nix at 0c53b6b8c2a3e46c68e04417e247bba660689c9d · NixOS/nixpkgs · GitHub

1 Like

Thanks for the suggestion!

I added the systemd service to my config and it seems like this fixed it. My current config is this:

{ pkgs, ... }:

{
	environment.systemPackages = [ pkgs.alsa-utils ];

	# ALSA provides a udev rule for restoring volume settings.
	services.udev.packages = [ pkgs.alsa-utils ];

	systemd.services.alsa-store =
		{ description = "Store Sound Card State";
			wantedBy = [ "multi-user.target" ];
			unitConfig.RequiresMountsFor = "/var/lib/alsa";
			unitConfig.ConditionVirtualization = "!systemd-nspawn";
			serviceConfig = {
				Type = "oneshot";
				RemainAfterExit = true;
				ExecStart = "${pkgs.coreutils}/bin/mkdir -p /var/lib/alsa";
				ExecStop = "${pkgs.alsa-utils}/sbin/alsactl store --ignore";
			};
		};

	security.rtkit.enable = true;

	services.pipewire = {
		enable = true;
		audio.enable = true;
		jack.enable = true;
		pulse.enable = true;
		alsa = {
			enable = true;
			support32Bit = true;
		};
	};
}
1 Like

Interesting. I’m by no means a sound expert, but that sounds like you’re actually somehow using alsa for sound instead of pipewire. Maybe you have some outdated config elsewhere, or some kind of legacy service that uses/enables alsa instead of using the pipewire emulation?

My full config is here. As far as I can tell the only option related to ALSA is this.

	services.pipewire = {
		alsa = {
			enable = true;
			support32Bit = true;
		};
	};

By the way, I moved to NixOS a couple of months ago and when I made my config from scratch I had the same problem until I added the sound.enable = true; option.

I was also having an issue with my audio after the removal of the option, though it wasn’t anything popping.

My mute-state light on my laptop keyboard was showing that sound was muted, however the system settings said otherwise. However I wasn’t able to actually hear any sound. Once I actually muted and unmuted the audio, the sound started working again. (I use playerctl for the media keys on the keyboard).

After adding this option, sound worked without needing to toggle the mute-state.

However I later realized that hardware.alsa.enablePersistence = true; does most of the things you included in the config snippet.

1 Like

It may make sense to open an issue on the nixpkgs repo for this, it may have been overlooked. If you enable pipewire alsa support, the config options that would allow it to actually work properly should be enabled as well, or at least point the user in the right direction on how to enable them.

I didn’t have this issue (yet) but I’m anticipating something breaking. I’m glad you found a solution!

2 Likes

I just tried using the hardware.alsa.enablePersistence = true; option and indeed it seems to fix the issue as well. Thanks!

Here’s what I swapped in the previous config:

 {
-       environment.systemPackages = [ pkgs.alsa-utils ];
-
-       # ALSA provides a udev rule for restoring volume settings.
-       services.udev.packages = [ pkgs.alsa-utils ];
-
-       systemd.services.alsa-store =
-               { description = "Store Sound Card State";
-                       wantedBy = [ "multi-user.target" ];
-                       unitConfig.RequiresMountsFor = "/var/lib/alsa";
-                       unitConfig.ConditionVirtualization = "!systemd-nspawn";
-                       serviceConfig = {
-                               Type = "oneshot";
-                               RemainAfterExit = true;
-                               ExecStart = "${pkgs.coreutils}/bin/mkdir -p /var/lib/alsa";
-                               ExecStop = "${pkgs.alsa-utils}/sbin/alsactl store --ignore";
-                       };
-               };
+       hardware.alsa.enablePersistence = true;
 
        security.rtkit.enable = true;
1 Like

I’ve added an issue here.

3 Likes

Cross posting for visibility (from the nixpkg repo issue):

I’m haven’t tried PipeWire yet, still using ALSA and PulseAudio, however after sound.enable was deprecated, I was having to go into alsamixer every time I rebooted my PC to unmute and turn volume up. hardware.alsa.enablePersistence = true; fixes this but every time I do a rebuild of NixOS I get this error:

warning: the following units failed: alsa-store.service

× alsa-store.service - Store Sound Card State
     Loaded: loaded (/etc/systemd/system/alsa-store.service; enabled; preset: enabled)
     Active: failed (Result: exit-code) since Sun 2024-08-11 11:37:38 EDT; 160ms ago
 Invocation: 7abcdd93411644cebc0d394b82d35c08
    Process: 48275 ExecStartPre=/nix/store/cnknp3yxfibxjhila0sjd1v3yglqssng-coreutils-9.5/bin/mkdir -p /var/lib/alsa (code=exited, status=0/SUCCESS)
    Process: 48276 ExecStart=/nix/store/ci53xg2rsd2c73rhz9rf2nrdh7i73xdp-alsa-utils-1.2.10/sbin/alsactl restore --ignore (code=exited, status=99)
   Main PID: 48276 (code=exited, status=99)
         IP: 0B in, 0B out
   Mem peak: 1.5M
        CPU: 8ms

Aug 11 11:37:38 nixos alsactl[48276]: Hardware is initialized using a generic method
Aug 11 11:37:38 nixos alsactl[48276]: alsa-lib main.c:1554:(snd_use_case_mgr_open) error: failed to import hw:3 use case configuration -2
Aug 11 11:37:38 nixos alsactl[48276]: Found hardware: "VirMIDI" "" "" "" ""
Aug 11 11:37:38 nixos alsactl[48276]: Hardware is initialized using a generic method
Aug 11 11:37:38 nixos alsactl[48276]: alsa-lib main.c:1554:(snd_use_case_mgr_open) error: failed to import hw:10 use case configuration -2
Aug 11 11:37:38 nixos alsactl[48276]: Found hardware: "Loopback" "Loopback Mixer" "" "" ""
Aug 11 11:37:38 nixos alsactl[48276]: Hardware is initialized using a generic method
Aug 11 11:37:38 nixos systemd[1]: alsa-store.service: Main process exited, code=exited, status=99/n/a
Aug 11 11:37:38 nixos systemd[1]: alsa-store.service: Failed with result 'exit-code'.
Aug 11 11:37:38 nixos systemd[1]: Failed to start Store Sound Card State.

EDIT: Well, I’ve switched over to PipeWire and so far so good. Audio levels persist after reboot.