diff options
author | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2009-05-24 23:13:23 +0000 |
---|---|---|
committer | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2009-05-24 23:13:23 +0000 |
commit | 5ebdee3577cb7c458d51460316e36ad393d73bc6 (patch) | |
tree | 7071853c20763954f915da1e95f3f3dbdbebdd68 /modules/services/audio | |
parent | f86e2e5d01574d9a9073c406b4f46c0ffeb35e8a (diff) | |
download | nixlib-5ebdee3577cb7c458d51460316e36ad393d73bc6.tar nixlib-5ebdee3577cb7c458d51460316e36ad393d73bc6.tar.gz nixlib-5ebdee3577cb7c458d51460316e36ad393d73bc6.tar.bz2 nixlib-5ebdee3577cb7c458d51460316e36ad393d73bc6.tar.lz nixlib-5ebdee3577cb7c458d51460316e36ad393d73bc6.tar.xz nixlib-5ebdee3577cb7c458d51460316e36ad393d73bc6.tar.zst nixlib-5ebdee3577cb7c458d51460316e36ad393d73bc6.zip |
* Continued refactoring the tree: moved most Upstart jobs (namely
those that run daemons) to modules/services. This probably broke some things since there are a few relative paths in modules (e.g. imports of system/ids.nix). * Moved some PAM modules out of etc/pam.d to the directories of NixOS modules that use them. svn path=/nixos/branches/modular-nixos/; revision=15717
Diffstat (limited to 'modules/services/audio')
-rw-r--r-- | modules/services/audio/alsa.nix | 92 | ||||
-rw-r--r-- | modules/services/audio/pulseaudio.nix | 94 |
2 files changed, 186 insertions, 0 deletions
diff --git a/modules/services/audio/alsa.nix b/modules/services/audio/alsa.nix new file mode 100644 index 000000000000..51c2e9244389 --- /dev/null +++ b/modules/services/audio/alsa.nix @@ -0,0 +1,92 @@ +# ALSA sound support. +{pkgs, config, ...}: + +###### interface +let + inherit (pkgs.lib) mkOption; + + 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; + + soundState = "/var/lib/alsa/asound.state"; + + # Alsalib seems to require the existence of this group, even if it's + # not used (e.g., doesn't own any devices). + group = { + name = "audio"; + gid = (import ../../../system/ids.nix).gids.audio; + }; + + job = { + name = "alsa"; + + job = '' + start on udev + stop on shutdown + + start script + + mkdir -m 0755 -p $(dirname ${soundState}) + + # Load some additional modules. + for mod in snd_pcm_oss; do + ${modprobe}/sbin/modprobe $mod || true + done + + # Restore the sound state. + ${alsaUtils}/sbin/alsactl -f ${soundState} restore + + end script + + respawn sleep 1000000 # !!! hack + + stop script + + # Save the sound state. + ${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]; + }; +} diff --git a/modules/services/audio/pulseaudio.nix b/modules/services/audio/pulseaudio.nix new file mode 100644 index 000000000000..05ec99bae929 --- /dev/null +++ b/modules/services/audio/pulseaudio.nix @@ -0,0 +1,94 @@ +{pkgs, config, ...}: + +###### interface +let + inherit (pkgs.lib) mkOption mkIf; + + uid = (import ../../../system/ids.nix).uids.pulseaudio; + gid = (import ../../../system/ids.nix).gids.pulseaudio; + + options = { + services = { + pulseaudio = { + enable = mkOption { + default = false; + description = '' + Whether to enable the PulseAudio system-wide audio server. + Note that the documentation recommends running PulseAudio + daemons per-user rather than system-wide on desktop machines. + ''; + }; + + logLevel = mkOption { + default = "notice"; + example = "debug"; + description = '' + A string denoting the log level: one of + <literal>error</literal>, <literal>warn</literal>, + <literal>notice</literal>, <literal>info</literal>, + or <literal>debug</literal>. + ''; + }; + }; + }; + }; +in + +###### implementation + +# For some reason, PulseAudio wants UID == GID. +assert uid == gid; + +mkIf config.services.pulseaudio.enable { + require = [ + options + ]; + + environment = { + + extraPackages = + pkgs.lib.optional + (!config.environment.cleanStart) + pkgs.pulseaudio; + }; + + users = { + extraUsers = [ + { name = "pulse"; + inherit uid; + group = "pulse"; + description = "PulseAudio system-wide daemon"; + home = "/var/run/pulse"; + } + ]; + + extraGroups = [ + { name = "pulse"; + inherit gid; + } + ]; + }; + + services = { + extraJobs = [{ + name = "pulseaudio"; + + job = '' + description "PulseAudio system-wide server" + + start on startup + stop on shutdown + + start script + test -d /var/run/pulse || \ + ( mkdir -p --mode 755 /var/run/pulse && \ + chown pulse:pulse /var/run/pulse ) + end script + + respawn ${pkgs.pulseaudio}/bin/pulseaudio \ + --system --daemonize \ + --log-level="${config.services.pulseaudio.logLevel}" + ''; + }]; + }; +} |