2008-11-22 17:29:05 -08:00
|
|
|
# ALSA sound support.
|
2009-10-12 10:27:57 -07:00
|
|
|
{ config, pkgs, ... }:
|
|
|
|
|
|
|
|
with pkgs.lib;
|
2007-02-28 16:36:00 -08:00
|
|
|
|
|
|
|
let
|
|
|
|
|
2009-07-16 08:01:56 -07:00
|
|
|
inherit (pkgs) alsaUtils;
|
|
|
|
|
|
|
|
soundState = "/var/lib/alsa/asound.state";
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
2011-09-14 11:20:50 -07:00
|
|
|
|
2008-11-22 17:29:05 -08:00
|
|
|
options = {
|
2011-09-14 11:20:50 -07:00
|
|
|
|
2008-11-22 17:29:05 -08:00
|
|
|
sound = {
|
|
|
|
|
|
|
|
enable = mkOption {
|
|
|
|
default = true;
|
2009-07-16 08:01:56 -07:00
|
|
|
description = ''
|
2008-11-22 17:29:05 -08:00
|
|
|
Whether to enable ALSA sound.
|
2009-07-16 08:01:56 -07:00
|
|
|
'';
|
2009-10-12 10:27:57 -07:00
|
|
|
merge = mergeEnableOption;
|
2008-11-22 17:29:05 -08:00
|
|
|
};
|
2011-09-14 11:20:50 -07:00
|
|
|
|
2010-03-03 06:01:13 -08:00
|
|
|
enableOSSEmulation = mkOption {
|
|
|
|
default = true;
|
2012-08-17 08:00:14 -07:00
|
|
|
description = ''
|
|
|
|
Whether to enable ALSA OSS emulation (with certain cards sound mixing may not work!).
|
|
|
|
'';
|
2010-03-03 06:01:13 -08:00
|
|
|
};
|
2007-02-28 16:36:00 -08:00
|
|
|
|
2008-11-22 17:29:05 -08:00
|
|
|
};
|
2011-09-14 11:20:50 -07:00
|
|
|
|
2008-11-22 17:29:05 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-07-16 08:01:56 -07:00
|
|
|
###### implementation
|
2011-09-14 11:20:50 -07:00
|
|
|
|
2009-07-16 08:01:56 -07:00
|
|
|
config = mkIf config.sound.enable {
|
2011-09-14 11:20:50 -07:00
|
|
|
|
2011-11-04 10:40:00 -07:00
|
|
|
environment.systemPackages = [ alsaUtils ];
|
2008-11-22 17:29:05 -08:00
|
|
|
|
2012-03-17 10:26:17 -07:00
|
|
|
boot.kernelModules = optional config.sound.enableOSSEmulation "snd_pcm_oss";
|
|
|
|
|
2009-10-12 11:09:34 -07:00
|
|
|
jobs.alsa =
|
2012-08-17 08:00:14 -07:00
|
|
|
{ description = "ALSA Volume Settings";
|
|
|
|
|
|
|
|
startOn = "stopped udevtrigger";
|
2008-11-22 17:29:05 -08:00
|
|
|
|
2009-07-16 08:01:56 -07:00
|
|
|
preStart =
|
|
|
|
''
|
|
|
|
mkdir -m 0755 -p $(dirname ${soundState})
|
2008-11-22 17:29:05 -08:00
|
|
|
|
2012-09-23 13:26:49 -07:00
|
|
|
# Try to restore the sound state.
|
|
|
|
${alsaUtils}/sbin/alsactl --ignore init || true
|
|
|
|
${alsaUtils}/sbin/alsactl --ignore -f ${soundState} restore || true
|
2009-07-16 08:01:56 -07:00
|
|
|
'';
|
2007-02-28 16:36:00 -08:00
|
|
|
|
2009-07-16 08:01:56 -07:00
|
|
|
postStop =
|
|
|
|
''
|
|
|
|
# Save the sound state.
|
2012-03-17 19:36:21 -07:00
|
|
|
${alsaUtils}/sbin/alsactl --ignore -f ${soundState} store
|
2009-07-16 08:01:56 -07:00
|
|
|
'';
|
|
|
|
};
|
2011-09-14 11:20:50 -07:00
|
|
|
|
2008-11-22 17:29:05 -08:00
|
|
|
};
|
2007-02-28 16:36:00 -08:00
|
|
|
|
|
|
|
}
|