2008-11-23 01:29:05 +00:00
|
|
|
# ALSA sound support.
|
2009-10-12 17:27:57 +00:00
|
|
|
{ config, pkgs, ... }:
|
|
|
|
|
|
|
|
with pkgs.lib;
|
2007-03-01 00:36:00 +00:00
|
|
|
|
|
|
|
let
|
|
|
|
|
2009-07-16 15:01:56 +00:00
|
|
|
inherit (pkgs) alsaUtils;
|
|
|
|
|
|
|
|
soundState = "/var/lib/alsa/asound.state";
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2008-11-23 01:29:05 +00:00
|
|
|
options = {
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2008-11-23 01:29:05 +00:00
|
|
|
sound = {
|
|
|
|
|
|
|
|
enable = mkOption {
|
|
|
|
default = true;
|
2009-07-16 15:01:56 +00:00
|
|
|
description = ''
|
2008-11-23 01:29:05 +00:00
|
|
|
Whether to enable ALSA sound.
|
2009-07-16 15:01:56 +00:00
|
|
|
'';
|
2009-10-12 17:27:57 +00:00
|
|
|
merge = mergeEnableOption;
|
2008-11-23 01:29:05 +00:00
|
|
|
};
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2010-03-03 14:01:13 +00:00
|
|
|
enableOSSEmulation = mkOption {
|
|
|
|
default = true;
|
|
|
|
description = ''
|
|
|
|
Whether to enable ALSA OSS emulation (with certain cards sound mixing may not work!).
|
|
|
|
'';
|
|
|
|
};
|
2007-03-01 00:36:00 +00:00
|
|
|
|
2008-11-23 01:29:05 +00:00
|
|
|
};
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2008-11-23 01:29:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-07-16 15:01:56 +00:00
|
|
|
###### implementation
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2009-07-16 15:01:56 +00:00
|
|
|
config = mkIf config.sound.enable {
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2009-07-16 15:01:56 +00:00
|
|
|
environment.systemPackages = [alsaUtils];
|
2007-06-10 20:17:51 +00:00
|
|
|
|
2009-07-16 15:01:56 +00:00
|
|
|
users.extraGroups = singleton
|
|
|
|
{ # Alsalib seems to require the existence of this group, even
|
|
|
|
# if it's not used (e.g., doesn't own any devices).
|
|
|
|
name = "audio";
|
|
|
|
gid = config.ids.gids.audio;
|
|
|
|
};
|
2008-11-23 01:29:05 +00:00
|
|
|
|
2009-10-12 18:09:34 +00:00
|
|
|
jobs.alsa =
|
2010-08-19 11:55:52 +00:00
|
|
|
{ startOn = "stopped udevtrigger";
|
2008-11-23 01:29:05 +00:00
|
|
|
|
2009-07-16 15:01:56 +00:00
|
|
|
preStart =
|
|
|
|
''
|
|
|
|
mkdir -m 0755 -p $(dirname ${soundState})
|
2008-11-23 01:29:05 +00:00
|
|
|
|
2009-07-16 15:01:56 +00:00
|
|
|
# Load some additional modules.
|
2010-03-03 14:01:13 +00:00
|
|
|
${optionalString config.sound.enableOSSEmulation
|
|
|
|
''
|
|
|
|
for mod in snd_pcm_oss; do
|
|
|
|
${config.system.sbin.modprobe}/sbin/modprobe $mod || true
|
|
|
|
done
|
|
|
|
''
|
|
|
|
}
|
2007-03-01 00:36:00 +00:00
|
|
|
|
2009-07-16 15:01:56 +00:00
|
|
|
# Restore the sound state.
|
2010-08-19 11:55:52 +00:00
|
|
|
${alsaUtils}/sbin/alsactl -f ${soundState} restore || true
|
2009-07-16 15:01:56 +00:00
|
|
|
'';
|
2007-03-01 00:36:00 +00:00
|
|
|
|
2009-07-16 15:01:56 +00:00
|
|
|
postStop =
|
|
|
|
''
|
|
|
|
# Save the sound state.
|
|
|
|
${alsaUtils}/sbin/alsactl -f ${soundState} store
|
|
|
|
'';
|
|
|
|
};
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2008-11-23 01:29:05 +00:00
|
|
|
};
|
2007-03-01 00:36:00 +00:00
|
|
|
|
|
|
|
}
|