Declarative audio config: How to start (and maybe use) JACK?

I switched from Ubuntu to NixOS around September. Yesterday I tried to set up audio programming in NixOS. I still can’t use JACK – and therefore not SuperCollider, or SuperCollider via Haskell (my goal).

I’ve only found one working NixOS audio config online (@magnetophon’s, described below). If you have another, I’d love to see it.

References and potential role models

After working on this problem for five hours I asked on Reddit for help. (I’m up to twelve hours now.) The one suggestion I received was that I could try a certain list of procedural changes, some subset of which, in some order, kind of worked for someone.

I’m hoping for a declarative solution instead. It seems from this Github issue that two users, @magnetophon and @MDeltaX, may have managed to do it.

What works for me, and what doesn’t

Sound works from the browser (I test using Youtube).

Supercollider claims to boot, and gives every visual indication of executing commands. However, it never generates audible speaker output. That’s true regardless of whether I start (and pless Play in) QJackctl.

I can open Cadence, hoping futz with connections and configurations. Cadence always tells me “jackdbus is not available,” and allows me no futzing. That’s true even after running jackd and/or jackdbus auto at the command line.

How are you supposed to start JACK?

Should it start automatically? Maybe I should pass some arguments to jackd, or different arguments to jackdbus?

Maybe relevant: jackdbus hangs ungracefully

When I run jackdbus auto it prints “no message buffer overruns” three times and then hangs; I can’t close the window hosting it, even if I run killall jackdbus (which I can run multiple times without receiving the usual “no process found” message, so it’s not actually killing it).

My configuration, and audio-related changes to it

Prior to working on audio, here’s what my configuration looked like. That’s the master branch. Here’s the branch where I’m experimenting with audio.

The first commit I made to the new “audio” branch consisted of these changes:

  • Add some apps to environment.systemPackages.
  • Enable Musnix as described in the Musnix readme.
  • Enable JACK as per the NixOS wiki section on JACK. (That WIKI page has a section marked “out of date”; I only acted on the notes preceding that warning.)

In the second commit, I tried to emulate the config of Github user @magnetophon. I

  • set more Musnix options
  • set services.tlp.enable = false
  • aped some stuff I don’t understand involving nixpkgs.config.packageOverrides and security.sudo.extraConfig
  • removed all mention of Pulseaudio

I also split the file audio.nix from the rest of configuration.nix.

Are my arguments in audio.nix reasonable?

My audio.nix file begins {config, lib, pkgs, options, modulesPath}:. Some of those arguments I added only because NixOS had complained in earlier versions of audio.nix that they were undefined. But some of those arguments – e.g. modulesPath – I don’t see defined anywhere in configuration.nix, which makes me nervous.