svn path=/nixos/branches/modular-nixos/; revision=16397

This commit is contained in:
Eelco Dolstra 2009-07-16 15:01:56 +00:00
parent 6119c399d8
commit 2cd3e205f4

View File

@ -1,92 +1,74 @@
# ALSA sound support. # ALSA sound support.
{pkgs, config, ...}: {pkgs, config, ...}:
###### interface
let let
inherit (pkgs.lib) mkOption; inherit (pkgs.lib) mkOption singleton mkIf;
options = {
sound = {
enable = mkOption {
default = true;
description = "
Whether to enable ALSA sound.
";
merge = pkgs.lib.mergeEnableOption;
};
};
};
in
###### implementation
let
inherit (pkgs.lib) mkIf;
# dangerous !
modprobe = config.system.sbin.modprobe;
inherit (pkgs) alsaUtils; inherit (pkgs) alsaUtils;
soundState = "/var/lib/alsa/asound.state"; soundState = "/var/lib/alsa/asound.state";
# Alsalib seems to require the existence of this group, even if it's in
# not used (e.g., doesn't own any devices).
group = { {
###### interface
options = {
sound = {
enable = mkOption {
default = true;
description = ''
Whether to enable ALSA sound.
'';
merge = pkgs.lib.mergeEnableOption;
};
};
};
###### implementation
config = mkIf config.sound.enable {
environment.systemPackages = [alsaUtils];
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"; name = "audio";
gid = config.ids.gids.audio; gid = config.ids.gids.audio;
}; };
job = { jobs = singleton
name = "alsa"; { name = "alsa";
job = '' startOn = "udev";
start on udev
stop on shutdown
start script
preStart =
''
mkdir -m 0755 -p $(dirname ${soundState}) mkdir -m 0755 -p $(dirname ${soundState})
# Load some additional modules. # Load some additional modules.
for mod in snd_pcm_oss; do for mod in snd_pcm_oss; do
${modprobe}/sbin/modprobe $mod || true ${config.system.sbin.modprobe}/sbin/modprobe $mod || true
done done
# Restore the sound state. # Restore the sound state.
${alsaUtils}/sbin/alsactl -f ${soundState} restore ${alsaUtils}/sbin/alsactl -f ${soundState} restore
'';
end script postStop =
''
respawn sleep 1000000 # !!! hack
stop script
# Save the sound state. # Save the sound state.
${alsaUtils}/sbin/alsactl -f ${soundState} store ${alsaUtils}/sbin/alsactl -f ${soundState} store
end script
''; '';
}; };
in
mkIf config.sound.enable {
require = [
# ../upstart-jobs/default.nix # config.services.extraJobs
# ../system/user.nix # users.*
# ? # config.environment.extraPackages
options
];
environment = {
extraPackages = [alsaUtils];
}; };
users = {
extraGroups = [group];
};
services = {
extraJobs = [job];
};
} }