[Nix-dev] Audio on nixos - small HOWTO

Marc Weber marco-oweber at gmx.de
Mon Sep 21 17:54:54 CEST 2009


So finally everything seems to work..

On the one hand you had just alsa. Alsa is the lowest (kernel) layer to
talk to hardware.

On top of that you usually run a daemon such as

a) pulseaudio
b) jackd
c) esd     (use pulseaudio instead)
d) artsd   (use pulseaudio instead ?)
e) ...

So howto set it up?

jackd:

Run the servers like this:

jackaudio server:
    jackd -d alsa
    jackd -d pulseaudio  (*)

  (*) make it output via pulseaudio, eg use this if you want to run both.
  There are other ways as well eg using alsa mixer plugins or such..


pulseaudio:
    Just run pulseaudio as normal user.





Now what can you do?
 pulseaudio:
  Use pavucontrol to adjust loudness of each application individually
  pulseaudio also can send music over network AFAIK (I haven't tried
  this yet)

 jackd:
    connect arbirtary input/output sources and pipe them through various
    filters (to be comitted to nixpkgs)
  
    Use qjackctl to change those connections
    Eg ardour only talks to jack




Howto make apps talk to those daemons which don't have native support?
a) There are oss wrappers for both.

b) (easiest way?): Use alsa tools and create a virtual device which will
    connect to those daemons:

    use a .asoundrc such as [1]

    nix-env -iA alsaPlugins
    export ALSA_PLUGIN_DIRS=~/.nix-profile/lib/alsa-lib

    Then just ask your application to talk to the alsa device.
    Example:
    mplayer -ao alsa:device=pulse  or device = jack

    mplayer has a native output dirver for pulse, jack though.


So finally I can control my sound the way I like on nixos.


Instead of exporting ALSA_PLUGIN_DIRS you can also install the 
alsaPluginWrapper script which adds this env var for you.
Then you can run ap23 skype on a amd64 system
connecting skype to pulseaudio :-)

However to use this you have to remove the jackaudio support else Skype
will crash (?). But forwarding sound to pulseaudio only works using
Skype.

Anyway: Enjoy!

Marc Weber

==========================================================

.asoundrc example [1]

pcm.pulse {
    type pulse
}

ctl.pulse {
    type pulse
}


pcm.jack {
    type jack
    playback_ports {
        0 alsa_pcm:playback_1
        1 alsa_pcm:playback_2
    }
    capture_ports {
        0 alsa_pcm:capture_1
        1 alsa_pcm:capture_2
    }
}



More information about the nix-dev mailing list