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

Avoid incorrectly setting LD_LIBRARY_PATH #408

Merged
merged 3 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions pkgs/python-utils/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,19 @@ let
ldLibraryPathConvertWrapper = pkgs.writeShellApplication {
inherit name;
text = ''
if test "''${REPLIT_RTLD_LOADER:-}" = "1" && test "''${REPLIT_NIX_CHANNEL:-}" != "legacy"
if test "''${REPLIT_NIX_CHANNEL:-}" = "legacy" || test "''${REPLIT_NIX_CHANNEL:-}" = "stable-21_11"
then
# activate RTLD loader!
export LD_AUDIT="${pkgs.replit-rtld-loader}/rtld_loader.so"
export REPLIT_LD_LIBRARY_PATH=${python-ld-library-path}:''${REPLIT_LD_LIBRARY_PATH:-}
else
export LD_LIBRARY_PATH=${python-ld-library-path}
if [ -n "''${PYTHON_LD_LIBRARY_PATH-}" ]; then
export LD_LIBRARY_PATH=''${PYTHON_LD_LIBRARY_PATH}:$LD_LIBRARY_PATH
fi
if [ -n "''${REPLIT_LD_LIBRARY_PATH-}" ]; then
export LD_LIBRARY_PATH=''${REPLIT_LD_LIBRARY_PATH}:$LD_LIBRARY_PATH
fi
else
# activate RTLD loader!
export LD_AUDIT="${pkgs.replit-rtld-loader}/rtld_loader.so"
export REPLIT_LD_LIBRARY_PATH=${python-ld-library-path}:''${REPLIT_LD_LIBRARY_PATH:-}
fi
exec "${bin}" "$@"
'';
Expand Down
32 changes: 26 additions & 6 deletions pkgs/python-wrapped/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,8 @@ import (
var PythonExePath string
var ReplitPythonLdLibraryPath string

func main() {
if ldAudit := os.Getenv("REPLIT_LD_AUDIT"); ldAudit != "" {
os.Setenv("LD_AUDIT", ldAudit)
}
os.Unsetenv("PYTHONNOUSERSITE")

// Set up environment for legacy nixpkgs
func legacy() {
ldLibraryPath := []string{}
for _, key := range []string{
"REPLIT_LD_LIBRARY_PATH",
Expand All @@ -30,7 +26,31 @@ func main() {
if len(ldLibraryPath) > 0 {
os.Setenv("LD_LIBRARY_PATH", strings.Join(ldLibraryPath, ":"))
}
}

// Set up environment for non-legacy nixpkgs
func modern() {
if ldAudit := os.Getenv("REPLIT_LD_AUDIT"); ldAudit != "" {
os.Setenv("LD_AUDIT", ldAudit)
}
if val, ok := os.LookupEnv("REPLIT_LD_LIBRARY_PATH"); ok && val != "" {
os.Setenv("REPLIT_LD_LIBRARY_PATH", strings.Join([]string{ReplitPythonLdLibraryPath, val}, ":"))
}
}

// returns whether a Nix channel works with RTLD loader
func channelWorksWithRtldLoader(channel string) bool {
return channel != "" && channel != "legacy" && channel != "stable-21_11"
}

func main() {
os.Unsetenv("PYTHONNOUSERSITE")

if val, ok := os.LookupEnv("REPLIT_NIX_CHANNEL"); ok && channelWorksWithRtldLoader(val) {
modern()
} else {
legacy()
}

if err := syscall.Exec(PythonExePath, os.Args, os.Environ()); err != nil {
panic(err)
Expand Down
Loading