Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nixos/jack,pulseaudio: fix pulse connection to jackd service #93431

Merged
merged 1 commit into from Nov 10, 2020

Conversation

sorki
Copy link
Member

@sorki sorki commented Jul 18, 2020

This fixes the case when Jack Audio Daemon is running
as a service via services.jack.jackd and Pulseaudio
running as a user service.

Two issues prevented connecting pulse with jackd:

  • Missing JACK_PROMISCUOUS_SERVER environment variable for pulse user service,
    resulting in pulse trying to access jackd as if it was running as part of
    the users session.
  • jackd not being able to access socket created by pulse due to socket
    created using user ID and users group. Change allows jackd to access
    the socket created by pulse correctly.

pulse now also autoloads module-jack-sink and module-jack-source
if services.jack.jackd.enable is set.

cc @asheshambasta @dustinlacewell @cole-h @gnidorah

TODOs:

  • Possibly add changelog entry
  • Update wiki page
Motivation for this change
Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

@sorki
Copy link
Member Author

sorki commented Jul 18, 2020

Quick workaround for current setups:

  systemd.services.jack.serviceConfig.SupplementaryGroups = [ "users" ];
  systemd.user.services.pulseaudio.environment.JACK_PROMISCUOUS_SERVER = "jackaudio";
  # sample jackd config
  services.jack = {
    jackd = {
      enable = true;
      # to force another sound card
      # extraOptions = [ "-dalsa" "-dhw:Solo" "-r44100" "-p1024" "-n2" ];
    };
  };

Rebuild + re-login and manually issue

pactl load-module module-jack-sink
pactl load-module module-jack-source

@ghost
Copy link

ghost commented Jul 19, 2020

I have these errors in systemctl --user status pulseaudio

июл 19 07:27:27 nixos pulseaudio[1179]: E: [pulseaudio] ltdl-bind-now.c: Не удалось открыть модуль module-jack-sink.so: module-jack-sink.so: cannot open shared object file: No such file or directory
июл 19 07:27:27 nixos pulseaudio[1179]: E: [pulseaudio] module.c: Failed to open module "module-jack-sink".
июл 19 07:27:27 nixos pulseaudio[1179]: E: [pulseaudio] ltdl-bind-now.c: Не удалось открыть модуль module-jack-source.so: module-jack-source.so: cannot open shared object file: No such file or directory
июл 19 07:27:27 nixos pulseaudio[1179]: E: [pulseaudio] module.c: Failed to open module "module-jack-source".

@asheshambasta
Copy link
Contributor

@gnidorah do you have pulseaudioFull installed?

@ghost
Copy link

ghost commented Jul 19, 2020

@asheshambasta

@gnidorah do you have pulseaudioFull installed?

Like environment.systemPackages = with pkgs; [ pulseaudioFull ];?
It doesn't help

@sorki
Copy link
Member Author

sorki commented Jul 19, 2020

@asheshambasta

@gnidorah do you have pulseaudioFull installed?

Like environment.systemPackages = with pkgs; [ pulseaudioFull ];?
It doesn't help

Good catch! Like this:

  hardware.pulseaudio = {
    package = pkgs.pulseaudioFull;
  };

Now I wonder if the package should default to pulseaudioFull when jack is enabled.

@sorki
Copy link
Member Author

sorki commented Jul 20, 2020

I've managed to get this working with 20.03 VM with user and groups like so

  users.users.jane = {
    isNormalUser = true;
    extraGroups = [ "wheel" "audio" "jackaudio" ];
  };

Most of the VM config:

  environment.systemPackages = with pkgs; [
    wget vim
    jack2Full
    qjackctl
    (mpv.override { jackaudioSupport = true; })
    pavucontrol
  ];

  sound.enable = true;
  hardware.pulseaudio = {
    enable = true;
    package = pkgs.pulseaudioFull;
  };

  services.jack.jackd = {
    enable = true;
    # extraOptions = [ "-dalsa" "-dhw:S3" "-r44100" "-p1024" "-n2" ];
  };

  services.xserver.enable = true;
  services.xserver.displayManager.sddm.enable = true;
  services.xserver.desktopManager.plasma5.enable = true;

  # Define a user account. Don't forget to set a password with ‘passwd’.
  users.users.jane = {
    isNormalUser = true;
    extraGroups = [ "wheel" "audio" "jackaudio" ]; # Enable ‘sudo’ for the user.
  };

Env vars might cause trouble if you don't reboot or log-out and log-in again.

@ghost
Copy link

ghost commented Aug 2, 2020

@sorki

This fixes the case when Jack Audio Daemon is running
as a service via services.jack.jackd and Pulseaudio
running as a user service.

Ok, I've added the following configuration rebooted and sound works for me without this PR

  services.jack.jackd.enable = true;
  users.extraUsers.gnidorah.extraGroups = [ "jackaudio" ];
  hardware.pulseaudio.enable = true;
  hardware.pulseaudio.systemWide = false;

Could you please provide a case when this PR is needed? Which programs to use for test etc?

@sorki
Copy link
Member Author

sorki commented Aug 26, 2020

Could you please provide a case when this PR is needed? Which programs to use for test etc?

Use case for this is running pulseaudio as a client for jackd, you can verify that the audio is routed thru pulse -> jack with pavucontrol - check if there's Jack sink in Output devices tab.

Good program for testing both servers is mpv, with this setup you should be able to play audio with both mpv -ao jack and mpv -ao pulse.

Also check that the jackd hooks the correct soundcard via systemctl status jack.

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for use cases, makes sense for me 😃

This fixes the case when Jack Audio Daemon is running
as a service via `services.jack.jackd` and Pulseaudio
running as a *user* service.

Two issues prevented connecting `pulse` with `jackd`:
* Missing `JACK_PROMISCUOUS_SERVER` environment variable for `pulse` user service,
  resulting in `pulse` trying to access `jackd` as if it was running as part of
  the users session.
* `jackd` not being able to access socket created by `pulse` due to socket
  created using user ID and `users` group. Change allows `jackd` to access
  the socket created by `pulse` correctly.

`pulse` now also autoloads `module-jack-sink` and `module-jack-source`
if `services.jack.jackd.enable` is set.

The default `pulse` package is now set to `pulseaudioFull` automatically
if `services.jack.jackd.enable` is set.
@sorki
Copy link
Member Author

sorki commented Sep 8, 2020

Fixed the issues with default package:

The default pulse package is now set to pulseaudioFull automatically
if services.jack.jackd.enable is set.

@sorki sorki marked this pull request as ready for review September 8, 2020 07:58
@ghost
Copy link

ghost commented Nov 9, 2020

@sorki This PR is waiting for a long time. Perhaps we should ask someone to merge it?

@sorki
Copy link
Member Author

sorki commented Nov 9, 2020

@worldofpeace do you think you can take a look? I think this was tested by few people and I'm using it with no issues for months now. The change is quite unobtrusive and only makes setup easier for jackd users.

@worldofpeace
Copy link
Contributor

Yeah, I've thought that it should do this for a while anyways.

@worldofpeace worldofpeace merged commit fcef646 into NixOS:master Nov 10, 2020
@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/nixos-and-linux-pro-audio/1788/15

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants