From ba5655198654bcf65ee6d13f4b5f34786ca6a26e Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 1 Mar 2007 00:36:00 +0000 Subject: [PATCH] * ALSA support: save/restore the volume settings, create device nodes in /dev/snd. svn path=/nixos/trunk/; revision=8124 --- system/options.nix | 9 +++++++ system/system.nix | 3 ++- system/upstart.nix | 6 +++++ upstart-jobs/alsa.nix | 38 +++++++++++++++++++++++++++ upstart-jobs/udev-rules/50-udev.rules | 9 +++++++ 5 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 upstart-jobs/alsa.nix diff --git a/system/options.nix b/system/options.nix index 8987ab2969a..b422815c33f 100644 --- a/system/options.nix +++ b/system/options.nix @@ -749,4 +749,13 @@ } + { + name = ["sound" "enable"]; + default = true; + description = " + Whether to enable ALSA sound. + "; + } + + ] diff --git a/system/system.nix b/system/system.nix index b68ca907032..e032bad07ab 100644 --- a/system/system.nix +++ b/system/system.nix @@ -197,7 +197,8 @@ rec { nixosRebuild nixosCheckout setuidWrapper - ]; + ] + ++ (if config.get ["sound" "enable"] then [pkgs.alsaUtils] else []); # We don't want to put all of `startPath' and `path' in $PATH, since diff --git a/system/upstart.nix b/system/upstart.nix index 7cd384ede53..3fa061e41c4 100644 --- a/system/upstart.nix +++ b/system/upstart.nix @@ -131,6 +131,12 @@ import ../upstart-jobs/gather.nix { inherit (pkgs) glibc pwdutils; }) + # ALSA sound support. + ++ optional ["sound" "enable"] + (import ../upstart-jobs/alsa.nix { + inherit (pkgs) kernel module_init_tools alsaUtils; + }) + # Handles the reboot/halt events. ++ (map (event: makeJob (import ../upstart-jobs/halt.nix { diff --git a/upstart-jobs/alsa.nix b/upstart-jobs/alsa.nix new file mode 100644 index 00000000000..620401de914 --- /dev/null +++ b/upstart-jobs/alsa.nix @@ -0,0 +1,38 @@ +{kernel, module_init_tools, alsaUtils}: + +let + + soundState = "/var/state/asound.state"; + +in + +{ + name = "alsa"; + + job = " +start on hardware-scan +stop on shutdown + +script + + # Load some additional modules. + export MODULE_DIR=${kernel}/lib/modules/ + for mod in snd_pcm_oss; do + ${module_init_tools}/sbin/modprobe $mod || true + done + + # Restore the sound state. + ${alsaUtils}/sbin/alsactl -f ${soundState} restore + +end script + +stop script + + # Save the sound state. + ${alsaUtils}/sbin/alsactl -f ${soundState} store + +end script + + "; + +} diff --git a/upstart-jobs/udev-rules/50-udev.rules b/upstart-jobs/udev-rules/50-udev.rules index ff2ed86888b..a4f1d73250a 100644 --- a/upstart-jobs/udev-rules/50-udev.rules +++ b/upstart-jobs/udev-rules/50-udev.rules @@ -28,3 +28,12 @@ KERNEL=="uinput", NAME="input/%k", MODE="0600" # Create a symlink for the CD-ROM device. KERNEL=="hd[a-z]", BUS=="ide", SYSFS{removable}=="1", SYSFS{device/media}=="cdrom", SYMLINK+="cdrom cdrom-%k" + + +# ALSA sound devices. +KERNEL=="controlC[0-9]*", NAME="snd/%k" +KERNEL=="hwC[D0-9]*", NAME="snd/%k" +KERNEL=="pcmC[D0-9cp]*", NAME="snd/%k" +KERNEL=="midiC[D0-9]*", NAME="snd/%k" +KERNEL=="timer", NAME="snd/%k" +KERNEL=="seq", NAME="snd/%k"