2008-11-23 01:29:05 +00:00
|
|
|
# ALSA sound support.
|
2014-04-14 14:26:48 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
2009-10-12 17:27:57 +00:00
|
|
|
|
2009-07-16 15:01:56 +00:00
|
|
|
{
|
2019-12-10 01:51:19 +00:00
|
|
|
imports = [
|
2024-07-15 07:33:34 +00:00
|
|
|
(lib.mkRemovedOptionModule [ "sound" ] "The option was heavily overloaded and can be removed from most configurations.")
|
2019-12-10 01:51:19 +00:00
|
|
|
];
|
2009-07-16 15:01:56 +00:00
|
|
|
|
2024-07-15 07:33:34 +00:00
|
|
|
options.hardware.alsa.enablePersistence = lib.mkOption {
|
|
|
|
type = lib.types.bool;
|
2024-07-13 10:56:18 +00:00
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Whether to enable ALSA sound card state saving on shutdown.
|
|
|
|
This is generally not necessary if you're using an external sound server.
|
|
|
|
'';
|
2008-11-23 01:29:05 +00:00
|
|
|
};
|
|
|
|
|
2024-07-15 07:33:34 +00:00
|
|
|
config = lib.mkIf config.hardware.alsa.enablePersistence {
|
2012-10-02 15:09:54 +00:00
|
|
|
# ALSA provides a udev rule for restoring volume settings.
|
2024-07-15 07:33:34 +00:00
|
|
|
services.udev.packages = [ pkgs.alsa-utils ];
|
2008-11-23 01:29:05 +00:00
|
|
|
|
2024-07-13 10:56:18 +00:00
|
|
|
systemd.services.alsa-store = {
|
|
|
|
description = "Store Sound Card State";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
unitConfig = {
|
|
|
|
RequiresMountsFor = "/var/lib/alsa";
|
|
|
|
ConditionVirtualization = "!systemd-nspawn";
|
|
|
|
};
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "oneshot";
|
|
|
|
RemainAfterExit = true;
|
|
|
|
ExecStartPre = "${pkgs.coreutils}/bin/mkdir -p /var/lib/alsa";
|
2024-07-15 07:33:34 +00:00
|
|
|
ExecStart = "${pkgs.alsa-utils}/sbin/alsactl restore --ignore";
|
|
|
|
ExecStop = "${pkgs.alsa-utils}/sbin/alsactl store --ignore";
|
2009-07-16 15:01:56 +00:00
|
|
|
};
|
2015-04-15 17:48:38 +00:00
|
|
|
};
|
2018-02-23 21:59:19 +00:00
|
|
|
};
|
2007-03-01 00:36:00 +00:00
|
|
|
}
|