Python: Difference between revisions
Added a sample python / nix-ld patch to allow compiled libraries to run with poetry or venv. |
Poetry fix was not working... it should work now :) |
||
Line 202: | Line 202: | ||
The following configuration automatically fix the dependencies :<syntaxhighlight lang="nixos" line="1"> | The following configuration automatically fix the dependencies :<syntaxhighlight lang="nixos" line="1"> | ||
let | let | ||
python = pkgs.python311; # | python = pkgs.python311; | ||
# https://github.com/NixOS/nixpkgs/blob/c339c066b893e5683830ba870b1ccd3bbea88ece/nixos/modules/programs/nix-ld.nix#L44 | |||
# > We currently take all libraries from systemd and nix as the default. | |||
pythonldlibpath = lib.makeLibraryPath (with pkgs; [ | |||
zlib | |||
zstd | |||
stdenv.cc.cc | |||
curl | |||
openssl | |||
attr | |||
libssh | |||
bzip2 | |||
libxml2 | |||
acl | |||
libsodium | |||
util-linux | |||
xz | |||
systemd | |||
]); | |||
patchedpython = (python.overrideAttrs ( | patchedpython = (python.overrideAttrs ( | ||
previousAttrs: { | previousAttrs: { | ||
# Add the nix-ld libraries to the LD_LIBRARY_PATH. | # Add the nix-ld libraries to the LD_LIBRARY_PATH. | ||
# creating a new library path from all desired libraries | # creating a new library path from all desired libraries | ||
postInstall = previousAttrs.postInstall + '' | postInstall = previousAttrs.postInstall + '' | ||
mv "$out/bin/python3.11" "$out/bin/unpatched_python3.11" | mv "$out/bin/python3.11" "$out/bin/unpatched_python3.11" | ||
cat << EOF >> "$out/bin/python3.11" | cat << EOF >> "$out/bin/python3.11" | ||
#!/run/current-system/sw/bin/bash | #!/run/current-system/sw/bin/bash | ||
export LD_LIBRARY_PATH="${ | export LD_LIBRARY_PATH="${pythonldlibpath}" | ||
exec "$out/bin/unpatched_python3.11" "\$@" | exec "$out/bin/unpatched_python3.11" "\$@" | ||
EOF | EOF | ||
chmod +x "$out/bin/python3.11" | chmod +x "$out/bin/python3.11" | ||
''; | |||
} | |||
)); | |||
# if you want poetry | |||
patchedpoetry = ((pkgs.poetry.override { python3 = patchedpython; }).overrideAttrs ( | |||
previousAttrs: { | |||
# same as above, but for poetry | |||
# not that if you dont keep the blank line bellow, it crashes :( | |||
postInstall = previousAttrs.postInstall + '' | |||
mv "$out/bin/poetry" "$out/bin/unpatched_poetry" | |||
cat << EOF >> "$out/bin/poetry" | |||
#!/run/current-system/sw/bin/bash | |||
export LD_LIBRARY_PATH="${pythonldlibpath}" | |||
exec "$out/bin/unpatched_poetry" "\$@" | |||
EOF | |||
chmod +x "$out/bin/poetry" | |||
''; | ''; | ||
} | } | ||
Line 242: | Line 260: | ||
patchedpython | patchedpython | ||
# | # if you want poetry | ||
patchedpoetry | |||
]; | ]; | ||
} | } |