2 { config, lib, pkgs, ... }:
6 (lib.mkRemovedOptionModule [ "sound" ] "The option was heavily overloaded and can be removed from most configurations.")
9 options.hardware.alsa.enablePersistence = lib.mkOption {
10 type = lib.types.bool;
13 Whether to enable ALSA sound card state saving on shutdown.
14 This is generally not necessary if you're using an external sound server.
18 config = lib.mkIf config.hardware.alsa.enablePersistence {
19 # ALSA provides a udev rule for restoring volume settings.
20 services.udev.packages = [ pkgs.alsa-utils ];
22 systemd.services.alsa-store = {
23 description = "Store Sound Card State";
24 wantedBy = [ "multi-user.target" ];
26 RequiresMountsFor = "/var/lib/alsa";
27 ConditionVirtualization = "!systemd-nspawn";
31 RemainAfterExit = true;
32 ExecStartPre = "${pkgs.coreutils}/bin/mkdir -p /var/lib/alsa";
33 ExecStart = "${pkgs.alsa-utils}/sbin/alsactl restore --ignore";
34 ExecStop = "${pkgs.alsa-utils}/sbin/alsactl store --ignore";