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

pythonPackages.sounddevice: fixed portaudio library path #43083

Merged
merged 1 commit into from Jul 7, 2018

Conversation

c0deaddict
Copy link
Member

@c0deaddict c0deaddict commented Jul 5, 2018

Motivation for this change

The path to the portaudio library is patched in sounddevice.py library. Problem is that sounddevice passes the path through a function _find_library that will try to find the relative library name somewhere on the filesystem. Unfortunately that function doesn't support the absolute library path that is patched in, and gives back None. Removing the _find_library function call resolves this issue.

To replicate this error put below content in a file default.nix:

with import <nixpkgs> {};

stdenv.mkDerivation rec {
  name = "env";
  env = buildEnv { name = name; paths = buildInputs; };
  builder = builtins.toFile "builder.sh" ''
    source $stdenv/setup; ln -s $env $out
  '';

  buildInputs = [
    portaudio
    python36
    python36Packages.sounddevice
  ];

  shellHook = ''
  '';
}

Then in the same directory run nix-shell --run python3

>>> import sounddevice
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/nix/store/ilm5zca38dxnyrsk8q5x91rl93jlzwk0-sounddevice/lib/python3.6/site-packages/sounddevice.py", line 2678, in <module>
    _initialize()
  File "/nix/store/ilm5zca38dxnyrsk8q5x91rl93jlzwk0-sounddevice/lib/python3.6/site-packages/sounddevice.py", line 2634, in _initialize
    _check(_lib.Pa_Initialize(), 'Error initializing PortAudio')
ffi.error: symbol 'Pa_Initialize' not found in library '<None>': python3: undefined symbol: Pa_Initialize
Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS)
  • 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 nox --run "nox-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)
  • Fits CONTRIBUTING.md.

Copy link
Member

@dotlambda dotlambda left a comment

Choose a reason for hiding this comment

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

@c0deaddict
Copy link
Member Author

Updated to 0.3.11 and changed the patch accordingly.

};

propagatedBuildInputs = [ cffi numpy portaudio ];

# No tests included nor upstream available.
doCheck = false;

prePatch = ''
substituteInPlace src/sounddevice.py --replace "'portaudio'" "'${portaudio}/lib/libportaudio.so.2'"
patches = [ ./fix-portaudio-library-path.patch ];
Copy link
Member

Choose a reason for hiding this comment

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

You should use substituteAll here instead of an additional postPatch phase. Have a look at e.g.

patches = [
(fetchpatch {
url = https://github.com/syncthing/syncthing-gtk/commit/b2535e5a9cdb31c4987ab7af37f62d58d38255b7.patch;
sha256 = "047v79wz2a9334gbzywlqwpacrk53s26ksvfqaddk06avv8742w7";
})
(substituteAll {
src = ./paths.patch;
killall = "${killall}/bin/killall";
syncthing = "${syncthing}/bin/syncthing";
})
];

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for your feedback. I've updated the patch to use substituteAll.

@dotlambda
Copy link
Member

@GrahamcOfBorg build python2.pkgs.sounddevice python3.pkgs.sounddevice

@GrahamcOfBorg
Copy link

Success on x86_64-linux (full log)

Attempted: python2.pkgs.sounddevice, python3.pkgs.sounddevice

Partial log (click to expand)

Successfully installed sounddevice-0.3.11
/build/sounddevice-0.3.11
post-installation fixup
shrinking RPATHs of ELF executables and libraries in /nix/store/s9ha5xhnh6q2g5vxxp6ckwg1m3wqxz1d-python3.6-sounddevice-0.3.11
strip is /nix/store/4qvrxzxa535y8304mk195x50b6p9607d-binutils-2.30/bin/strip
stripping (with command strip and flags -S) in /nix/store/s9ha5xhnh6q2g5vxxp6ckwg1m3wqxz1d-python3.6-sounddevice-0.3.11/lib
patching script interpreter paths in /nix/store/s9ha5xhnh6q2g5vxxp6ckwg1m3wqxz1d-python3.6-sounddevice-0.3.11
checking for references to /build in /nix/store/s9ha5xhnh6q2g5vxxp6ckwg1m3wqxz1d-python3.6-sounddevice-0.3.11...
/nix/store/sckha760amhjznr3lvdhbvi9kqmp9nkq-python2.7-sounddevice-0.3.11
/nix/store/s9ha5xhnh6q2g5vxxp6ckwg1m3wqxz1d-python3.6-sounddevice-0.3.11

@GrahamcOfBorg
Copy link

Success on aarch64-linux (full log)

Attempted: python2.pkgs.sounddevice, python3.pkgs.sounddevice

Partial log (click to expand)

Successfully installed sounddevice-0.3.11
/build/sounddevice-0.3.11
post-installation fixup
shrinking RPATHs of ELF executables and libraries in /nix/store/1dbj9nasy4bm10clj2cl3hyi4znyrzvq-python3.6-sounddevice-0.3.11
strip is /nix/store/0pjsgkxz0rp5baycq5sp2s72lrr5q9sg-binutils-2.30/bin/strip
stripping (with command strip and flags -S) in /nix/store/1dbj9nasy4bm10clj2cl3hyi4znyrzvq-python3.6-sounddevice-0.3.11/lib
patching script interpreter paths in /nix/store/1dbj9nasy4bm10clj2cl3hyi4znyrzvq-python3.6-sounddevice-0.3.11
checking for references to /build in /nix/store/1dbj9nasy4bm10clj2cl3hyi4znyrzvq-python3.6-sounddevice-0.3.11...
/nix/store/5rmy5rlcjiv1v5fsw13wb1lc2pzn6q54-python2.7-sounddevice-0.3.11
/nix/store/1dbj9nasy4bm10clj2cl3hyi4znyrzvq-python3.6-sounddevice-0.3.11

@dotlambda dotlambda merged commit 9291a3c into NixOS:master Jul 7, 2018
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