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
|
|
|
|
|
2008-11-22 17:29:05 -08:00
|
|
|
options = {
|
2009-07-16 08:01:56 -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
|
|
|
};
|
2007-02-28 16:36:00 -08:00
|
|
|
|
2008-11-22 17:29:05 -08:00
|
|
|
};
|
2009-07-16 08:01:56 -07:00
|
|
|
|
2008-11-22 17:29:05 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-07-16 08:01:56 -07:00
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf config.sound.enable {
|
|
|
|
|
|
|
|
environment.systemPackages = [alsaUtils];
|
2007-06-10 13:17:51 -07:00
|
|
|
|
2009-07-16 08:01:56 -07: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-22 17:29:05 -08:00
|
|
|
|
2009-10-12 11:09:34 -07:00
|
|
|
jobs.alsa =
|
2009-11-06 14:19:17 -08:00
|
|
|
{ startOn = "started udev";
|
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
|
|
|
|
2009-07-16 08:01:56 -07:00
|
|
|
# Load some additional modules.
|
|
|
|
for mod in snd_pcm_oss; do
|
|
|
|
${config.system.sbin.modprobe}/sbin/modprobe $mod || true
|
|
|
|
done
|
2007-02-28 16:36:00 -08:00
|
|
|
|
2009-07-16 08:01:56 -07:00
|
|
|
# Restore the sound state.
|
|
|
|
${alsaUtils}/sbin/alsactl -f ${soundState} restore
|
|
|
|
'';
|
2007-02-28 16:36:00 -08:00
|
|
|
|
2009-07-16 08:01:56 -07:00
|
|
|
postStop =
|
|
|
|
''
|
|
|
|
# Save the sound state.
|
|
|
|
${alsaUtils}/sbin/alsactl -f ${soundState} store
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2008-11-22 17:29:05 -08:00
|
|
|
};
|
2007-02-28 16:36:00 -08:00
|
|
|
|
|
|
|
}
|