diff --git a/modules/services/audio/alsa.nix b/modules/services/audio/alsa.nix index fa63bc74cfc5d7..ff08f21a48574b 100644 --- a/modules/services/audio/alsa.nix +++ b/modules/services/audio/alsa.nix @@ -45,29 +45,19 @@ in environment.systemPackages = [ alsaUtils ]; - boot.kernelModules = optional config.sound.enableOSSEmulation "snd_pcm_oss"; - - jobs.alsa = - { description = "ALSA Volume Settings"; - - startOn = "stopped udevtrigger"; + # ALSA provides a udev rule for restoring volume settings. + services.udev.packages = [ alsaUtils ]; - preStart = - '' - mkdir -m 0755 -p $(dirname ${soundState}) - - # Try to restore the sound state. - ${alsaUtils}/sbin/alsactl --ignore init || true - ${alsaUtils}/sbin/alsactl --ignore -f ${soundState} restore || true - ''; + boot.kernelModules = optional config.sound.enableOSSEmulation "snd_pcm_oss"; - postStop = - '' - # Save the sound state. - ${alsaUtils}/sbin/alsactl --ignore -f ${soundState} store - ''; + boot.systemd.services."alsa-store" = + { description = "Store Sound Card State"; + wantedBy = [ "shutdown.target" ]; + before = [ "shutdown.target" ]; + unitConfig.DefaultDependencies = "no"; + serviceConfig.Type = "oneshot"; + serviceConfig.ExecStart = "${alsaUtils}/sbin/alsactl store --ignore"; }; - }; }