-
Notifications
You must be signed in to change notification settings - Fork 330
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
python: add patchelf option #840
Conversation
'') ++ (lib.optional cfg.venv.patchelf '' | ||
if [ -d "$VIRTUAL_ENV" ] | ||
then | ||
${autopatchelf}/bin/autopatchelf --libs ${config.devenv.profile}/lib --path $VIRTUAL_ENV |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know the devenv code well enough but find this approach interesting.
Here a few hints: 1. Avoid running patchelf repeatably as might change the binary on every run (sometimes with weird side effects). 2. Make sure that ${config.devenv.profile}/lib
cannot be garbage collected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the feedback!
- Avoid running patchelf repeatably as might change the binary on every run (sometimes with weird side effects).
Indeed. Maybe storing the profile inside VIRTUAL_ENV
and comparing it is a good enough approach.
- Make sure that ${config.devenv.profile}/lib cannot be garbage collected.
I presumed the profile is not GCed, as it has a GC root that in .devenv
. Not entirely sure whether this is a good presumption though.
macOS has install_name_tools instead of patchelf. Maybe just adding |
@@ -135,6 +145,12 @@ in | |||
description = "Whether `pip install` should avoid outputting messages during devenv initialisation."; | |||
}; | |||
|
|||
venv.patchelf = lib.mkOption { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if this should be a no-op on non-elf architectures to not break macOS by accident.
I think the method that we use by fixing the interpreter itself now works well in 1.0 branch, we're only waiting for the merge of NixOS/nixpkgs#275701 |
@bobvanderlinden Something like this might be helpfull for ruby too. I added this
to a RoR projects config. I didn't find another way to make the |
The method used in NixOS/nixpkgs#275701 should also work for Ruby, but it currently has only been implemented for Python. |
Oh, great. I found that PR before but lost track while reading through it. |
Going to close this for now, we found a way to make virtualenv work well with Nix. To solve glibc issues we'll have to use LD_AUDIT hack or something similar. Let me know if there's any other reason we'd have this |
Currently Python package managers install packages with prebuilt binaries, which might refer to libraries that the program is not able to find.
LD_LIBRARY_PATH
is a solution, but seeps through to sub-processes, sometimes resulting in surprising errors due to conflicting libraries/interpreters.I have been experimenting with using autopatchelf on venv. A tool that finds ELF files, looks up their dependencies in a set of
lib
directories and patches the ELF files to use thoselib
directories specifically. It seems to work fairly well.There are a few downsides though:
.so*
files in the venv.I mostly wanted to give this option some consideration compared to
LD_LIBRARY_PATH
. Feel free to decline this. I'm open to all feedback.