2008-11-23 02:29:05 +01:00
|
|
|
# ALSA sound support.
|
|
|
|
{pkgs, config}:
|
2007-03-01 01:36:00 +01:00
|
|
|
|
2008-11-23 02:29:05 +01:00
|
|
|
###### interface
|
2007-03-01 01:36:00 +01:00
|
|
|
let
|
2008-11-23 02:29:05 +01:00
|
|
|
inherit (pkgs.lib) mkOption;
|
2007-03-01 01:36:00 +01:00
|
|
|
|
2008-11-23 02:29:05 +01:00
|
|
|
options = {
|
|
|
|
sound = {
|
|
|
|
|
|
|
|
enable = mkOption {
|
|
|
|
default = true;
|
|
|
|
description = "
|
|
|
|
Whether to enable ALSA sound.
|
|
|
|
";
|
|
|
|
merge = pkgs.lib.mergeEnableOption;
|
|
|
|
};
|
2007-03-01 01:36:00 +01:00
|
|
|
|
2008-11-23 02:29:05 +01:00
|
|
|
};
|
|
|
|
};
|
2007-03-01 01:36:00 +01:00
|
|
|
in
|
2007-03-06 01:07:00 +01:00
|
|
|
|
2008-11-23 02:29:05 +01:00
|
|
|
###### implementation
|
|
|
|
let
|
2008-11-23 02:29:25 +01:00
|
|
|
inherit (pkgs.lib) mkIf;
|
2008-11-23 02:29:05 +01:00
|
|
|
|
|
|
|
# dangerous !
|
|
|
|
modprobe = config.system.sbin.modprobe;
|
|
|
|
inherit (pkgs) alsaUtils;
|
|
|
|
|
|
|
|
soundState = "/var/lib/alsa/asound.state";
|
2007-06-10 22:17:51 +02: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-23 02:29:05 +01:00
|
|
|
group = {
|
|
|
|
name = "audio";
|
|
|
|
gid = (import ../system/ids.nix).gids.audio;
|
|
|
|
};
|
2007-06-10 22:17:51 +02:00
|
|
|
|
2008-11-23 02:29:05 +01:00
|
|
|
job = {
|
|
|
|
name = "alsa";
|
2007-03-01 01:36:00 +01:00
|
|
|
|
2008-11-23 02:29:05 +01:00
|
|
|
job = ''
|
|
|
|
start on udev
|
|
|
|
stop on shutdown
|
2007-03-01 01:36:00 +01:00
|
|
|
|
2008-11-23 02:29:05 +01:00
|
|
|
start script
|
2007-03-20 12:04:45 +01:00
|
|
|
|
2008-11-23 02:29:05 +01:00
|
|
|
mkdir -m 0755 -p $(dirname ${soundState})
|
2007-03-01 01:36:00 +01:00
|
|
|
|
2008-11-23 02:29:05 +01:00
|
|
|
# Load some additional modules.
|
|
|
|
for mod in snd_pcm_oss; do
|
|
|
|
${modprobe}/sbin/modprobe $mod || true
|
|
|
|
done
|
2007-03-01 01:36:00 +01:00
|
|
|
|
2008-11-23 02:29:05 +01:00
|
|
|
# Restore the sound state.
|
|
|
|
${alsaUtils}/sbin/alsactl -f ${soundState} restore
|
2007-03-01 01:36:00 +01:00
|
|
|
|
2008-11-23 02:29:05 +01:00
|
|
|
end script
|
2007-03-01 01:50:17 +01:00
|
|
|
|
2008-11-23 02:29:05 +01:00
|
|
|
respawn sleep 1000000 # !!! hack
|
|
|
|
|
|
|
|
stop script
|
|
|
|
|
|
|
|
# Save the sound state.
|
|
|
|
${alsaUtils}/sbin/alsactl -f ${soundState} store
|
|
|
|
|
|
|
|
end script
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
in
|
|
|
|
|
2008-11-23 02:29:25 +01:00
|
|
|
mkIf config.sound.enable {
|
2008-11-23 02:29:05 +01:00
|
|
|
require = [
|
|
|
|
(import ../upstart-jobs/default.nix) # config.services.extraJobs
|
|
|
|
# (import ../system/user.nix) # users.*
|
|
|
|
# (import ?) # config.environment.extraPackages
|
|
|
|
options
|
|
|
|
];
|
2007-03-01 01:36:00 +01:00
|
|
|
|
2008-11-23 02:29:05 +01:00
|
|
|
environment = {
|
2008-11-23 02:29:25 +01:00
|
|
|
extraPackages = [alsaUtils];
|
2008-11-23 02:29:05 +01:00
|
|
|
};
|
2007-03-01 01:36:00 +01:00
|
|
|
|
2008-11-23 02:29:05 +01:00
|
|
|
users = {
|
2008-11-23 02:29:25 +01:00
|
|
|
extraGroups = [group];
|
2008-11-23 02:29:05 +01:00
|
|
|
};
|
2007-03-01 01:36:00 +01:00
|
|
|
|
2008-11-23 02:29:05 +01:00
|
|
|
services = {
|
2008-11-23 02:29:25 +01:00
|
|
|
extraJobs = [job];
|
2008-11-23 02:29:05 +01:00
|
|
|
};
|
2007-03-01 01:36:00 +01:00
|
|
|
}
|