2008-11-22 17:29:05 -08:00
|
|
|
# ALSA sound support.
|
2008-12-04 07:48:27 -08:00
|
|
|
{pkgs, config, ...}:
|
2007-02-28 16:36:00 -08:00
|
|
|
|
2008-11-22 17:29:05 -08:00
|
|
|
###### interface
|
2007-02-28 16:36:00 -08:00
|
|
|
let
|
2008-11-22 17:29:05 -08:00
|
|
|
inherit (pkgs.lib) mkOption;
|
2007-02-28 16:36:00 -08:00
|
|
|
|
2008-11-22 17:29:05 -08:00
|
|
|
options = {
|
|
|
|
sound = {
|
|
|
|
|
|
|
|
enable = mkOption {
|
|
|
|
default = true;
|
|
|
|
description = "
|
|
|
|
Whether to enable ALSA sound.
|
|
|
|
";
|
|
|
|
merge = pkgs.lib.mergeEnableOption;
|
|
|
|
};
|
2007-02-28 16:36:00 -08:00
|
|
|
|
2008-11-22 17:29:05 -08:00
|
|
|
};
|
|
|
|
};
|
2007-02-28 16:36:00 -08:00
|
|
|
in
|
2007-03-05 16:07:00 -08:00
|
|
|
|
2008-11-22 17:29:05 -08:00
|
|
|
###### implementation
|
|
|
|
let
|
2008-11-22 17:29:25 -08:00
|
|
|
inherit (pkgs.lib) mkIf;
|
2008-11-22 17:29:05 -08:00
|
|
|
|
|
|
|
# dangerous !
|
|
|
|
modprobe = config.system.sbin.modprobe;
|
|
|
|
inherit (pkgs) alsaUtils;
|
|
|
|
|
|
|
|
soundState = "/var/lib/alsa/asound.state";
|
2007-06-10 13:17:51 -07:00
|
|
|
|
|
|
|
# Alsalib seems to require the existence of this group, even if it's
|
|
|
|
# not used (e.g., doesn't own any devices).
|
2008-11-22 17:29:05 -08:00
|
|
|
group = {
|
|
|
|
name = "audio";
|
2009-05-29 07:25:56 -07:00
|
|
|
gid = config.ids.gids.audio;
|
2008-11-22 17:29:05 -08:00
|
|
|
};
|
2007-06-10 13:17:51 -07:00
|
|
|
|
2008-11-22 17:29:05 -08:00
|
|
|
job = {
|
|
|
|
name = "alsa";
|
2007-02-28 16:36:00 -08:00
|
|
|
|
2008-11-22 17:29:05 -08:00
|
|
|
job = ''
|
|
|
|
start on udev
|
|
|
|
stop on shutdown
|
2007-02-28 16:36:00 -08:00
|
|
|
|
2008-11-22 17:29:05 -08:00
|
|
|
start script
|
2007-03-20 04:04:45 -07:00
|
|
|
|
2008-11-22 17:29:05 -08:00
|
|
|
mkdir -m 0755 -p $(dirname ${soundState})
|
2007-02-28 16:36:00 -08:00
|
|
|
|
2008-11-22 17:29:05 -08:00
|
|
|
# Load some additional modules.
|
|
|
|
for mod in snd_pcm_oss; do
|
|
|
|
${modprobe}/sbin/modprobe $mod || true
|
|
|
|
done
|
2007-02-28 16:36:00 -08:00
|
|
|
|
2008-11-22 17:29:05 -08:00
|
|
|
# Restore the sound state.
|
|
|
|
${alsaUtils}/sbin/alsactl -f ${soundState} restore
|
2007-02-28 16:36:00 -08:00
|
|
|
|
2008-11-22 17:29:05 -08:00
|
|
|
end script
|
2007-02-28 16:50:17 -08:00
|
|
|
|
2008-11-22 17:29:05 -08:00
|
|
|
respawn sleep 1000000 # !!! hack
|
|
|
|
|
|
|
|
stop script
|
|
|
|
|
|
|
|
# Save the sound state.
|
|
|
|
${alsaUtils}/sbin/alsactl -f ${soundState} store
|
|
|
|
|
|
|
|
end script
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
in
|
|
|
|
|
2008-11-22 17:29:25 -08:00
|
|
|
mkIf config.sound.enable {
|
2008-11-22 17:29:05 -08:00
|
|
|
require = [
|
2009-05-24 16:13:23 -07:00
|
|
|
# ../upstart-jobs/default.nix # config.services.extraJobs
|
2009-05-19 16:14:45 -07:00
|
|
|
# ../system/user.nix # users.*
|
|
|
|
# ? # config.environment.extraPackages
|
2008-11-22 17:29:05 -08:00
|
|
|
options
|
|
|
|
];
|
2007-02-28 16:36:00 -08:00
|
|
|
|
2008-11-22 17:29:05 -08:00
|
|
|
environment = {
|
2008-11-22 17:29:25 -08:00
|
|
|
extraPackages = [alsaUtils];
|
2008-11-22 17:29:05 -08:00
|
|
|
};
|
2007-02-28 16:36:00 -08:00
|
|
|
|
2008-11-22 17:29:05 -08:00
|
|
|
users = {
|
2008-11-22 17:29:25 -08:00
|
|
|
extraGroups = [group];
|
2008-11-22 17:29:05 -08:00
|
|
|
};
|
2007-02-28 16:36:00 -08:00
|
|
|
|
2008-11-22 17:29:05 -08:00
|
|
|
services = {
|
2008-11-22 17:29:25 -08:00
|
|
|
extraJobs = [job];
|
2008-11-22 17:29:05 -08:00
|
|
|
};
|
2007-02-28 16:36:00 -08:00
|
|
|
}
|