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