Skip to content

Commit

Permalink
python: remove LD_LIBRARY_PATH hack from running python environment
Browse files Browse the repository at this point in the history
  • Loading branch information
vlaci committed Oct 30, 2024
1 parent 5c046ee commit 58ee89f
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/modules/languages/python.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ let
python = cfg.package;
requiredPythonModules = cfg.package.pkgs.requiredPythonModules;
makeWrapperArgs = [
"--set"
"DEVENV_LD_LIBRARY_PATH_PREFIX"
libraries
"--prefix"
"LD_LIBRARY_PATH"
":"
Expand All @@ -39,6 +42,21 @@ let
follows = [ "nixpkgs" ];
};

pth_file =
let
exec_content = ''
ld_library_path_var = "DYLD_LIBRARY_PATH" if sys.platform == "darwin" else "LD_LIBRARY_PATH"
ld_library_path = os.environ.get(ld_library_path_var)
ld_library_path_prefix = os.environ.get("DEVENV_LD_LIBRARY_PATH_PREFIX")
if ld_library_path and ld_library_path_prefix:
if ld_library_path == ld_library_path_prefix:
del os.environ[ld_library_path_var]
else:
os.environ[ld_library_path_var] = ld_library_path.removeprefix(ld_library_path_prefix + ":")
'';
in
pkgs.writeText "devenv.pth" ''import os; exec("""${builtins.replaceStrings [ "\n" ] [ "\\n" ] exec_content}""")'';

initVenvScript =
let
USE_UV_SYNC = cfg.uv.sync.enable && builtins.compareVersions cfg.uv.package.version "0.4.4" >= 0;
Expand Down Expand Up @@ -80,6 +98,7 @@ let
''
}
echo "${package.interpreter}" > "$VENV_PATH/.devenv_interpreter"
cp ${pth_file} "$VENV_PATH/${package.sitePackages}/devenv.pth"
fi
source "$VENV_PATH"/bin/activate
Expand Down Expand Up @@ -157,6 +176,7 @@ let
if "''${UV_SYNC_COMMAND[@]}"
then
echo "$ACTUAL_UV_CHECKSUM" > "$UV_CHECKSUM_FILE"
cp ${pth_file} "$VENV_PATH/${package.sitePackages}/devenv.pth"
else
echo "uv sync failed. Run 'uv sync' manually." >&2
fi
Expand Down Expand Up @@ -206,6 +226,7 @@ let
if ''${POETRY_INSTALL_COMMAND[@]}
then
echo "$ACTUAL_POETRY_CHECKSUM" > "$POETRY_CHECKSUM_FILE"
cp ${pth_file} ".venv/${package.sitePackages}/devenv.pth"
else
echo "Poetry install failed. Run 'poetry install' manually."
fi
Expand Down

0 comments on commit 58ee89f

Please sign in to comment.